
Module Module1


    Sub main()
        Dim user2 As List(Of String) = New List(Of String)(Split(Console.ReadLine(), " "))
        Dim countryMax As Long = user2(0)
        Dim terepoMax As UInt64 = user2(1)
        Dim user3 As List(Of String) = New List(Of String)(Split(Console.ReadLine(), " "))
        Dim towns As New List(Of Long)(Array.ConvertAll(user3.ToArray, Function(i As String) CLng(i)))

        Dim nextTown As Long = 0
        Dim worpCount = 0

        Dim checkPoint As New List(Of Long)
        Dim result As Long = -1

        'checkPoint.Add(0)   ' 初期位置を訪れた場所に追加

        Dim flgWorped As Boolean = False
        Do

            'Console.WriteLine(nextTown + 1 & "の町へようこそ！")
            ' 既に訪れているか
            If checkPoint.Contains(nextTown) And Not flgWorped Then
                flgWorped = True

                ' 何番目に訪れた街か再チェック
                Dim numberTown As Long

                For i = 0 To checkPoint.Count - 1
                    If checkPoint(i) = nextTown Then
                        numberTown = i
                    End If
                Next
                'Console.WriteLine("この街は" & numberTown & "回目に訪れました。今は " & nextTown + 1 & "の街にいます。")

                ' x = n[総数] % ( c[現在の街数] - t[先頭から数えた街数] ) + t
        Dim x = ((terepoMax - worpCount) Mod (worpCount - numberTown))    ' これが後進むべき数

                ' 残り飛ぶ回数
                terepoMax = worpCount + x
                'Console.WriteLine("mod=" & x & "残り：" & worpCount & " / " & terepoMax)

            Else

            End If
                '移動先を訪れた場所に追加
                checkPoint.Add(nextTown)
              ' 次の街へWorp
      if terepoMax <= worpCount Then exit do
              nextTown = towns(nextTown) - 1
              worpCount += 1
            'Console.WriteLine(nextTown & ", " & towns(nextTown))
        Loop While terepoMax >= worpCount

      result = nextTown + 1


        Console.WriteLine(result)
    End Sub
end module