n,m=map(int,input().split()) a=list(map(int,input().split())) ans=1 for i in reversed(range(m)): if ans==1: ans=a[i] continue if a[i]==1:continue if a[i]>=ans: ans-=1 print(ans)