#include using namespace std; typedef long long LL; #define CIN_ONLY if(1) struct cww{cww(){ CIN_ONLY{ ios::sync_with_stdio(false);cin.tie(0); } }}star; #define fin "\n" #define FOR(i,bg,ed) for(int i=(bg);i<(ed);i++) #define REP(i,n) FOR(i,0,n) #define ALL(v) (v).begin(),(v).end() #define fi first #define se second #define pb push_back #define DEBUG if(0) #define REC(ret, ...) std::function template inline bool chmin(T &l,T r) {bool a=l>r;if(a)l=r;return a;} template inline bool chmax(T &l,T r) {bool a=l istream& operator>>(istream &is,vector &v){ for(auto &it:v)is>>it; return is; } int main(){ int N,M; cin>>N; vector a(N); cin>>a; cin>>M; vector b(M); cin>>b; sort(ALL(b)); reverse(ALL(b)); vector ord(N); iota(ALL(ord),0); int res=100; do{ auto c= b; int id=0; bool flag=true; REP(i,N){ while(id=a[ord[i]])break; id++; } if(id==M){ flag=false; break; } c[id]-=a[ord[i]]; } if(flag)chmin(res,id+1); }while(next_permutation(ALL(ord))); if(res==100)res=-1; cout<