#include int n,t,x,m,a[10];main(){for(t=n=m=10;n--;)scanf("%d",a+n);for(;x<3;)m--?x+=a[m]==t:(m=10,t--);printf("%d\n",t);}