#Lutece3331. On Duty
On Duty
Description
For a high-load system like Lutece, it is necessary to schedule multiple people on duty to ensure stability. In 3202, Lutece becomes very popular, and there are system engineers responsible for its maintenance, numbered from to .
There is a duty roster denoted by . On the first day, Engineer is on duty, and on the second day, Engineer is on duty. For each day starting from the second day, if Engineer is on duty today and Engineer was on duty yesterday, then Engineer will be on duty tomorrow. The duty roster is pre-planned in such a way that the engineer on duty today will not be on duty tomorrow.
The question is: Who is on duty on the -th day?
Input
The first line contains two integers , indicating the number of engineers and the day we want to know.
For the next lines, each line contains integers, representing the duty roster . It is guaranteed that only the numbers on the diagonal are , i.e. only .
Output
Output one integer , indicating Engineer will be on duty on the -th day.
Samples
3 7
0 3 2
3 0 3
2 1 0
1
Note
For the example:
- On the second day, Engineer will be on duty tomorrow, i.e. the third day, since Engineer is on duty today and Engineer was on duty yesterday.
- On the third day, Engineer will be on duty tomorrow, i.e. the fourth day, since Engineer is on duty today and Engineer was on duty yesterday.
Resources
电子科技大学第十四届 ACM 趣味程序设计竞赛