n,m = map(int,input().split()) s = list(map(int,input().split())) p = 1 for i in s[::-1]: if p == 1: p = i elif i >= p: p -= 1 print(p)