import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class JosephCircle {
public int newJoseph(int n, int[] p, int k) {
List<Integer> num = new ArrayList<Integer>();
for( int i = 0; i < n; i++ ) num.add(i);
int t = k, index = 0;
for( int i = 0; i < n - 1; i++ ) {
index = ( index + t ) % num.size();
num.remove(index);
t = p[index];
if(index == num.size()) index=0;
}
return num.get(0)+1;
}
public int oldJoseph(int n, int k){
int w = 0;
for( int i = 2; i <= n; i++ ){
w = (w+k)%i;
}
return w;
}
public static void main(String[] args) {
JosephCircle jc = new JosephCircle();
Scanner scan = new Scanner(System.in);
int n,k;
int[] p = new int[100];
System.out.print("Enter N = ");n = scan.nextInt();
System.out.print("Enter P[] = ");
for(int i = 0; i < n; i++){
p[i] = scan.nextInt();
}
System.out.print("Enter K = ");k = scan.nextInt();
System.out.println();
System.out.println("Survivor is No." + jc.newJoseph(n,p,k));
}
}