#include <iostream>
#include <vector>
#include <cstdio>
#include <string>
#include <cmath>
#include <algorithm>
#include <climits>
#include <map>

#define ll long long
#define MAX 25 * 1e13
#define N  200010

#define SIZE(A) ((int)A.size())
#define LEN(A) ((int)A.length())
#define MP(A,B) make_pair(A,B)
#define PB(X) push_back(X)
#define EB(X) emplace_back(X)
#define REP(i,a) for(int i=0;i<(a);++i)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define range(a) a.begin(), a.end()
#define VI vector<int>;

using namespace std;
int MOD = 1000000007;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll k;
  int n;
  cin >> n >> k;
  vector<int> to(n+1);
  REP(i,n) {
    int a;
    cin >> a;
    to[i+1] = a;
  }
  int lens = 0;
  vector<int> seen(n+1);
  int pos = 1;
  seen[1] = 1;
  vector<int> path(1);
  path[0] = 1;

  int last = 0;
  for(int i = 0; i < n; ++i) {// times;
    pos = to[pos];
    if( seen[pos] == 1 ) { // aready in seen
      path.push_back(pos);
      last = pos;
      break;
    }
    else {
      seen[pos] = 1;
      path.push_back(pos);
    }
  }
  ll lenp = path.size();
  ll lenr = 0;
  int st = 0;
  for(int i = 0; i < lenp; ++i ) {
    if(path[i] == last) {
      st = i;
      lenr = lenp - 1 - i;
      break;
    }
  }
  REP(i,lenp) {
    cout << path[i] << "  ";
  }
  cout << endl;

  path.pop_back();
  lenp--;

  if( k <= lenp) {
    cout << path[k-1] << endl;

  }
  else {
    k -= lenp;
    ll r = k % lenr;
    int ret = path[r+st];
    cout << ret << endl;
  }
  return 0;

}

