import java.util.Random; import java.util.Scanner; class Main{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); Random ran = new Random(); int N = sc.nextInt(); int K = sc.nextInt(); int x = 0; int y = 0; while(x < N){ x = sc.nextInt(); if((N-1)%(K+1) == (x-1)%(K+1))y++; else y = 0; if(y == 5){ System.out.println(N); break; } x += ran.nextInt(K)+1; } System.out.println(x); } }