a[51],m;main(t){for(gets(&t);~scanf("%d",&t);)for(m=a[t],*a=m?m:t;t--;a[t+1]=m?m:t);*a=!printf("%d",*a);}