#include #define ll long long #define INF 1000000005 #define MOD 1000000007 #define EPS 1e-10 #define rep(i,n) for(int i=0;i<(int)n;++i) #define each(a, b) for(auto (a): (b)) #define all(v) (v).begin(),(v).end() #define fi first #define se second #define pb push_back #define show(x) cout<<#x<<" = "<<(x)<P; const int MAX_N = 30; int main() { cin.tie(0); ios::sync_with_stdio(false); int n; cin >> n; vector a(n); rep(i,n){ cin >> a[i]; } int m; cin >> m; vector b(m); rep(i,m){ cin >> b[i]; } int sma = accumulate(all(a),0); int smb = accumulate(all(b),0); if(sma > smb){ cout << "-1\n"; return 0; } sort(all(b),greater()); int ans = INF; do { vector vol(m,0); rep(nw,n){ bool flag = false; rep(i,m){ if(a[nw] + vol[i] <= b[i]){ vol[i] += a[nw]; flag = true; break; } } if(!flag){ break; } if(nw == n-1){ int cnt = 0; rep(i,m){ if(vol[i]){ cnt++; } } ans = min(ans,cnt); } } } while (next_permutation(a.begin(), a.end())); if(ans == INF){ cout << "-1\n"; }else{ cout << ans << endl; } return 0; }