#include <bits/stdc++.h> // #include <atcoder/all> using namespace std; // using namespace atcoder; #define rep(i, a, n) for(int i = a; i < n; i++) #define rrep(i, a, n) for(int i = a; i >= n; i--) #define inr(l, x, r) (l <= x && x < r) #define ll long long #define ld long double // using mint = modint1000000007; // using mint = modint998244353; constexpr int IINF = 1001001001; constexpr ll INF = 1e18; template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;} template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;} template <class T, T (*op)(T, T), T (*e)()> class SegmentTree { int _n, size, log; vector<T> d; void update(int k) { d[k] = op(d[2 * k], d[2 * k + 1]); } public: SegmentTree() : SegmentTree(0) {} explicit SegmentTree(int n) : SegmentTree(vector<T>(n, e())) {} // explicit で明示的に型を指定する explicit SegmentTree(const vector<T> &v) : _n(int(v.size())) { // sizeは_nを超える最小の2のべき乗 size = 1; while(size < _n) size *= 2, log++; // log は木の高さ(sizeの桁数) log = 0; while (!(size & (1 << log))) log++; d = vector<T>(2*size, e()); for(int i = 0; i < _n; i++) d[size+i] = v[i]; for(int i = size-1; i >= 1; i--){ update(i); } } void set(int p, T x){ assert(0 <= p && p < _n); p += size; d[p] = x; for(int i = 1; i <= log; i++) update(p >> i); } void apply(int p, T x){ set(p, op(x, d[p+size])); } T get(int p) const { assert(0 <= p && p < _n); return d[p+size]; } T prod(int l, int r) const { assert(0 <= l && l <= r && r <= _n); T sml = e(), smr = e(); l += size; r += size; while(l < r){ if(l&1) sml = op(sml, d[l++]); if(r&1) smr = op(d[--r], smr); l >>= 1; r >>= 1; } return op(sml, smr); } T all_prod() const {return d[1]; }; // f(op(a[l], a[l + 1], ..., a[r - 1])) = trueとなる最大のr template <bool (*f)(T)> int max_right(int l) const { return max_right(l, [](T x) { return f(x); }); } template <class F> int max_right(int l, F f) const { assert(0 <= l && l <= _n); assert(f(e())); if (l == _n) return _n; l += size; T sm = e(); do { while (l % 2 == 0) l >>= 1; if (!f(op(sm, d[l]))) { while (l < size) { l = (2 * l); if (f(op(sm, d[l]))) { sm = op(sm, d[l]); l++; } } return l - size; } sm = op(sm, d[l]); l++; } while ((l & -l) != l); return _n; } // f(op(a[l], a[l + 1], ..., a[r - 1])) = true となる最小の l template <bool (*f)(T)> int min_left(int r) const { return min_left(r, [](T x) { return f(x); }); } template <class F> int min_left(int r, F f) const { assert(0 <= r && r <= _n); assert(f(e())); if (r == 0) return 0; r += size; T sm = e(); do { r--; while (r > 1 && (r % 2)) r >>= 1; if (!f(op(d[r], sm))) { while (r < size) { r = (2 * r + 1); if (f(op(d[r], sm))) { sm = op(d[r], sm); r--; } } return r + 1 - size; } sm = op(d[r], sm); } while ((r & -r) != r); return 0; } }; using S = ll; S op(S a, S b) { return min(a, b); } S e() { return 9e18; } int main(){ ll n, x; cin >> n >> x; x--; vector<int> a(n); rep(i, 0, n){ cin >> a[i]; chmin(a[i], n+1); } SegmentTree<S, op, e> st(vector<S>(n+2, 0)); rep(i, 0, n) st.set(a[i], st.get(a[i])+1); rep(i, 0, n+1){ // にぶたん int r = st.max_right(0, [&](ll tmp){return tmp > 0;}); a.push_back(r); st.set(r, st.get(r)+1); st.set(a[i%n], st.get(a[i%n])-1); } // rep(i, n, 2*n+1){ // cout << a[i] << ' '; // } // cout << endl; if(x < 2*n+1){ cout << a[x] << endl; }else{ set<int> s; int l = 2*n; rrep(i, 2*n, 0){ if(s.count(a[i])) break; l--; s.insert(a[i]); } int sz = (2*n-l); // cout << l << ' ' << sz << endl; x -= l+1; cout << a[l+1+x%sz] << endl; } return 0; }