Under construction

Still being built. Things may change

Attendance Check

Interview

Time limit1sMemory limit1024 MB

Summary
Given a permutation forming one cycle, find the student who responds last when the calling chain starts at student k.
Level

Easy3 of 10

Topics
Implementation, Simulation, Array, Graph
Solved
No attempts yet

Problem

Teacher Neringa has devised a new way to check whether all students have gathered for class. There are NN students in the class, and each student is assigned to remember the name of exactly one other student.

Each day before class, Neringa randomly picks one student and calls that student's name. The student who is called then calls the name of the student assigned to them; that student in turn calls the name of the student assigned to them; and so on, until some student calls the name of the student Neringa originally called.

Neringa set up the assignments (deciding who remembers whose name) so that, when every student is present, calling the students this way is guaranteed to call each student exactly once. In other words, the assignments form a single cycle that includes all students.

Determine which student responds last, assuming all students are present.

Input

The first line contains two positive integers: the number of students NN and the number kk of the student Neringa calls.

The second line contains NN positive integers a1,a2,…,aNa_1, a_2, \dots, a_N, where aia_i is the number of the student assigned to student ii.

Output

Print a single integer — the number of the last student to respond.

Constraints

  • 1≤N, k≤10001 \le N,\ k \le 1000
  • 1≤ai≤N1 \le a_i \le N for every ii.
  • All aia_i are distinct.

Examples1

  1. Example 1

    Input
    5 2
    4 3 5 2 1
    
    Expected output
    4