N,M=(int(i) for i in input (). split ()) A=[int (i) for i in input (). split ()] print (A) C=[int (i) for i in range(N)] for i in range (M): R=A[i] C.pop(A[i]) C.insert(0,R) print (C[0])