import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException {
// Fast input reading
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] firstLine = br.readLine().trim().split("\\s+");
int k = Integer.parseInt(firstLine[0]);
long n = Long.parseLong(firstLine[1]);
String[] secondLine = br.readLine().trim().split("\\s+");
int[] initial = new int[k];
for(int i=0;i<k;i++) initial[i] = Integer.parseInt(secondLine[i]);
// Initialize frequency array
int maxA = k + 2;
int[] freq = new int[maxA+1];
for(int i=0;i<k;i++) {
if(initial[i] <= maxA) freq[initial[i]]++;
}
// Compute initial mex
int mex =1;
while(mex <= maxA && freq[mex] >0) mex++;
// Use a list to store the sequence
ArrayList<Integer> sequence = new ArrayList<>();
for(int i=0;i<k;i++) sequence.add(initial[i]);
// To detect cycles, use a HashMap with hash of last few mex steps
// Since storing full window is too large, we assume cycles emerge early
// and use pair of (mex, last few ai's) as state
// Here, we use the mex and the frequency array's state
// But frequency array is too big, so alternatively, use the mex progression
// and store the ai's from some window
// To implement a feasible cycle detection, store ai's in order and map when a certain window repeats
// However, with k up to1e6, it's not practical. Instead, proceed to simulate up to limit
// and assume that cycle length is small, e.g., up to 1e6 +1e6
// To speed up, limit the simulation steps
long limit = n;
long step =k;
// To store the ai's for cycle detection, use a map from a tuple to step
// But it's too slow. Instead, store the ai's in a list and use two pointers to find cycle
// Implement Floyd's Tortoise and Hare for cycle detection based on ai's
// Implementing Floyd's cycle detection
// First, simulate steps and store ai's
// Use two pointers, one moving one step at a time, the other two steps
// When they meet, cycle detected
// However, to simplify, simulate steps and store in a map the mex after each step
// along with the current step number
// Here, we proceed to simulate up to a certain number of steps
// and detect cycles by storing the mex and the step
// Initialize a map to store mex and step
// But since mex can be up to k+1, and state is not only mex, ignore cycle detection
// and simulate up to some steps
// To handle large k and n, we will simulate up to k + 1000 steps and assume cycle is within
// these steps
// If n <=k, just return initial[n-1]
if(n <=k){
System.out.println(initial[(int)(n-1)]);
return;
}
// Simulate up to k + 100000 steps
long simLimit = Math.min(n, (long)(k) + 1000000);
for(; step < simLimit; step++) {
int ai = mex;
sequence.add(ai);
if(ai <= maxA) freq[ai]++;
// Remove oldest
int remove_x = sequence.get((int)(step -k));
if(remove_x <= maxA) {
freq[remove_x]--;
if(remove_x < mex && freq[remove_x] ==0){
mex = remove_x;
}
}
// Update mex
while(mex <= maxA && freq[mex] >0) mex++;
}
if(n <= sequence.size()){
System.out.println(sequence.get((int)(n-1)));
return;
}
// Now, find the cycle in the remaining steps
// Record the first occurrence of each possible mex value after simLimit steps
// Then, find the cycle length and start
// To detect cycle, store the last cycleLength ai's
// Here, we use a map from a state to step
// State can be last p ai's where p is small, e.g., 20
// But with the assumption that cycle repeats within some steps
// Use a pattern matching approach
// Alternatively, simulate further and find when the sequence repeats
// But without precise cycle detection, proceed as follows:
// For simplicity, assume that after simLimit, the cycle has been established
// And the cycle length is the last few steps
// Extract the cycle from the end of the sequence
// Here, it's better to implement proper cycle detection, but without it,
// we proceed to simulate up to n if it's feasible
// But n can be up to1e12, so it's not feasible
// Thus, better implement proper Floyd's cycle detection
// Implement two pointers, tortoise and hare
// Tortoise moves one step, hare moves two steps
// Initialize
int tortoiseIndex = (int)simLimit;
ArrayList<Integer> tortoiseSeq = new ArrayList<>(sequence);
ArrayList<Integer> hareSeq = new ArrayList<>(sequence);
// Continue simulation until cycle is detected
// Define maximum additional steps to prevent infinite loop
long maxAdditional = 1000000;
boolean cycleFound = false;
long cycleStart = -1;
long cycleLength = -1;
// To speed up, use a map to store the first occurrence of a state
// Define state as last p ai's, where p=20
// Adjust p based on expected cycle lengths
// Here, use p=20
int p =20;
Map<String, Long> stateMap = new HashMap<>();
for(; step < simLimit + maxAdditional && step <n; step++){
int ai = mex;
sequence.add(ai);
if(ai <= maxA) freq[ai]++;
// Remove oldest
int remove_x = sequence.get((int)(step -k));
if(remove_x <= maxA) {
freq[remove_x]--;
if(remove_x < mex && freq[remove_x] ==0){
mex = remove_x;
}
}
// Update mex
while(mex <= maxA && freq[mex] >0) mex++;
// Build state string from last p ai's
if(sequence.size() >= p){
StringBuilder sb = new StringBuilder();
for(int i=(int)(step -p+1); i<=step; i++) sb.append(sequence.get(i)).append(",");
String state = sb.toString();
if(stateMap.containsKey(state)){
long first = stateMap.get(state);
cycleStart = first;
cycleLength = step - first;
cycleFound = true;
break;
}
else{
stateMap.put(state, step);
}
}
}
if(!cycleFound){
// No cycle detected within the limit
// Output the last computed ai
System.out.println(sequence.get((int)(n-1)));
return;
}
// Now, cycleStart is the step where the cycle starts
// cycleLength is the length of the cycle
if(n <= cycleStart){
System.out.println(sequence.get((int)(n-1)));
return;
}
else{
long offset = n - cycleStart;
long posInCycle = cycleStart + (offset % cycleLength);
System.out.println(sequence.get((int)(posInCycle -1)));
}
}
}