#include using namespace std; #define ll long long #define pb push_back #define F first #define S second #define mk make_pair #define pii pair < int , bool > const int maxn = 2e6 + 100; const ll inf = 1e18; int a[maxn] , check[maxn] , k; pii seg[4 * maxn]; void build(int l = 0 , int r = k + 2 , int id = 1){ if (r - l == 1){ seg[id].F = check[l]; if (seg[id].F) seg[id].S = 1; return; } int mid = (l + r) >> 1; build(l , mid , id << 1 | 0); build(mid , r , id << 1 | 1); seg[id].S = (seg[id << 1 | 0].S && seg[id << 1 | 1].S); return; } int get (int l = 0 , int r = k + 2 , int id = 1){ if (r - l == 1){ if (seg[id].S) return -1; return l; } int mid = (l + r) >> 1; if (!seg[id << 1 | 0].S) return get(l , mid , id << 1 | 0); if (!seg[id << 1 | 1].S) return get(mid , r , id << 1 | 1); return -1; } void update(int idx , int x , int l = 0 , int r = k + 2 , int id = 1){ if (idx < l || idx >= r) return; if (r - l == 1){ seg[id].F += x; if (seg[id].F) seg[id].S = 1; else seg[id].S = 0; return; } int mid = (l + r) >> 1; update(idx , x , l , mid , id << 1 | 0); update(idx , x , mid , r , id << 1 | 1); seg[id].S = (seg[id << 1 | 0].S && seg[id << 1 | 1].S); return; } int main() { ll n; cin >> k >> n; check[0] = 1; for (int i = 0; i < k; i++){ cin >> a[i]; if (a[i] <= k + 1) check[a[i]]++; } build(); ll y = -1 , u = 0; bool g = 0; for (int i = k; i <= 2 * k; i++ , u++){ int t = get(); //cout << "t : " << t << "\n"; if (t == k + 1 && !g){ a[i] = t; y = i; g = 1; } update(t , 1); update(a[u] , -1); a[i] = t; } if (n <= 2 * k) return cout << a[n - 1] << "\n" , 0; n -= (y - k); n--; ll p = n % (k + 1); int q = (y - k + p); cout << a[q] << "\n"; return 0; }