import sequtils,strutils,algorithm proc r():any=stdin.readLine.parseInt proc R():any=stdin.readLine.split.map(parseInt).sorted(cmp,Descending) var N=r() K=1 shl N A=R() M=r() B=R() S=newSeq[int]K for n in 0..0:S[n]+=A[i])) var U=S.mapIt(B[0]-it>=0) if U[K-1]:quit "1",0 for i,b in B[1..^1]: var V=S.mapIt(false) for x,a in U:(if a:(for y,s in S:(if (x and y)==0 and b-s>=0:V[x xor y]=true))) U=V if U[K-1]:quit $(i+2),0 echo -1