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