N, M = map(int, input().split())
A = list(map(int, input().split()))

pos = 0
for a in reversed(A):
    if pos == 0:
        pos = a - 1
    else:
        if pos < a:
            pos -= 1

print(pos + 1)