N, M = map(int, input().split()) top = 1 a = list(map(int, input().split())) for i in range(M-1, -1, -1): if top == 1: top = a[i] elif top <= a[i]: top -= 1 print(top)