import sequtils,strutils,strscans,algorithm,math,future,macros template get*():string = stdin.readLine() #.strip() template `max=`*(x,y:typed):void = x = max(x,y) template optPow{`^`(2,n)}(n:int) : int = 1 shl n template If*(ex:untyped):untyped = (if not(ex) : continue) import times let N = get().parseInt() A = get().split().map(parseInt).sorted(cmp,Descending) # toy <20 M = get().parseInt() B = get().split().map(parseInt).sorted(cmp,Descending) # box <20 var state = newSeqWith(2^N,0) for n in 0 ..< 2^N: for ia in 0 ..< N: If: (n and 2^ia) == 2^ia state[n] += A[ia] # 各状態の体積の和 var ans = state.mapIt(B[0] - it >= 0) if ans[2^N - 1] : echo 1 quit() for i,b in B[1..^1]: var n_ans = state.mapIt(false) for x,a in ans: If: a for y,s in state: If: (x and y) == 0 If: b - s >= 0 n_ans[x xor y] = true ans = n_ans if ans[2^N - 1] : echo i+2 quit() echo -1