N,M = map(int, input().split()) A = map(int, reversed(input().split())) t = 1 for a in A: if t == 1: t = a elif a >= t: t -= 1 print(t)