$1[@q=1]=$n+=<>;$q=pop@q,map$_<=$n&$#$_<0&&(@$_=(0,@$q),@q=($_,@q)),$q-($==grep$q>>$_&1,0..14),$q+$=while@q;print$#$n