n=int(input())
temp=list(map(int,input().split()))
ans=n
x=1
for i in range(1,n//2):
    if temp[i]-temp[i-1]!=2:
        x=0
if x==0:
    for i in range(1,n//2):
        if temp[i]-temp[i-1]>1:
            ans-=temp[i]-temp[i-1]      
    print(ans)
else:
    print(0)