ll@N,@A,@B;rep(i,N){ll@p;p&1?A--:0;p>1?B--:0;if(A<0|B<0){wt(i+1);return 0;}}wt(-1);