N, M = map(int, input().split()) As = list(map(int, input().split())) pos = 1 for a in As[::-1]: if pos == 1: pos = a elif a >= pos: pos -= 1 print(pos)