#include <bits/stdc++.h>
//                    #include <ext/pb_ds/assoc_container.hpp>
//                    #include <ext/pb_ds/tree_policy.hpp>

                    using ll = long long;
                    using ld = long double;
                    #define rep(i, a, n) for(ll i = (a); i < (n); i++)
                    #define per(i, a, n) for(ll i = (n-1); i >= (a); i--)
                    #define F first
                    #define S second
                    #define maxx(a, b) a = max(a, b)
                    #define minn(a, b) a = min(a, b)
                    #define db(x) cerr << #x << " = " << x << endl
                    #define N 1111111
                    #define mod 1000000007
                    #define rt return
                    #define inf 123456789123456789ll

                    using namespace std;
                    random_device rd;
                    mt19937 mt(rd());
//                    using namespace __gnu_pbds;
//
//                    typedef tree<pair<ll,ll>, null_type, less<pair<ll,ll>>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

                    #define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

                    void err(istream_iterator<string> it) {}
                    template<typename T, typename... Args>
                    void err(istream_iterator<string> it, T a, Args... args)
                    {
                        cerr << *it << " = " << a << endl;
                        err(++it, args...);
                    }

                    ll modlaber(ll a, ll m = mod)
                    {
                        rt ((a+m)%m+m)%m;
                    }

                    ll n,k;
                    vector<ll> g[N];
                    bool used[N];
                    ll l;
                    vector<ll> path;

                    void dfs(ll v = 1)
                    {
                        path.push_back(v);
                        l++;
                        used[v] = 1;
                        for(auto x: g[v])
                            if(!used[x])
                                dfs(x);
                            else
                            {
                                if(l > k)
                                    cout<<path[modlaber(k, ll(path.size()))];
                                else
                                {
//                                    db(x);
                                    vector<ll> small;
                                    ll where = 0;
                                    while(path[where] != x)
                                        where++;
//                                    db(where);
                                    k -= where;
                                    while(where < path.size())
                                        small.push_back(path[where++]);
//                                    db(where);
                                    ll m = modlaber(k, ll(small.size()));
                                    cout<<small[m];
                                }
                            }
                    }

                    int main()
                    {
                        ios_base::sync_with_stdio(0);
                        cin.tie(0);
                        cout.tie(0);

                        cin>>n>>k;
                        rep(i,0,n)
                        {
                            ll j; cin>>j;
                            g[i+1].push_back(j);
//                            g[j].push_back(i);
                        }

                        dfs();

                        rt 0;
                    }















Measured memory_bytes: 59004