## COCI '19 Contest 5 #2 Političari

View as PDF

Points: 7 (partial)
Time limit: 1.0s
Memory limit: 512M

Problem type
Allowed languages
Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, CommonLisp, D, Dart, F#, Forth, Fortran, Go, Groovy, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, Nim, ObjC, OCaml, Octave, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig

All politicians of an unknown, completely invented and totally unrealistic country are spending their time accusing each other on national television instead of doing their jobs. It all started one Sunday afternoon when politician number 1 was a guest in the first episode of a (now very popular) talk show. During the show, he accused the politician number 2 for the poor state of the country. Naturally, in the second episode of the show the guest was politician number 2. The talk show host told his guest that politician number 1 accused him and politician number 2 then blamed some other politician. The newly blamed politician was the guest in the next show where the host told him that. . . Even today, after almost 20 years, a new politician is a guest in each episode of the show where he is being told by whom he was accused for the poor state in the country. That politician then blames another politician and the vicious cycle continues. To make things more interesting, we have exclusively found out that each politician has a fixed strategy on how to behave during the show. More precisely, each politician knows who to blame based on the person who blamed him in previous show. We will provide you with this information and hope you will be able to write a program that calculates what politician will be the guest of the -th show.

#### Input

The first line contains integers and from the task description.

The -th of the next lines contains integers where -th integer tells us who will be blamed by the -th politician if he was blamed by politician number in the last show.

You can assume that no politician will ever blame himself. Therefore, none of the numbers in -th line of matrix will be equal to . Similarly, note that the -th number in the -th matrix row will always be equal to and can be disregarded.

#### Output

In a single line you should output the number of a politician that will be the guest of the -th episode of the talk show.

#### Scoring

In the test cases worth a total of points, it will hold .

#### Sample Input 1

2 4
0 2
1 0

#### Sample Output 1

2

#### Sample Input 2

3 7
0 3 2
3 0 3
2 1 0

#### Sample Output 2

1

#### Sample Input 3

4 7
0 4 3 2
4 0 4 1
2 1 0 1
3 2 3 0

#### Sample Output 3

3