x[1<<18],c,*p;main(j){for(scanf("%d",&c);~scanf("%d",&j);*x=1)for(p=x;p-x*p?p[j]=1+*p:0;printf("%d",x[c]-1);}