#include using namespace std; int main() { int N, M; vector A, B; cin >> N; A.resize(N); for (int i = 0; i < N; i++) { cin >> A[i]; } cin >> M; B.resize(M); for (int i = 0; i < M; i++) { cin >> B[i]; } sort(A.begin(), A.end()); sort(B.begin(), B.end(), greater()); B.push_back(1000); int ans = M + 1; do { int now = 0; vector C(M + 1); for (int i = 0; i < N; i++) { if (C[now] + A[i] <= B[now]) { C[now] += A[i]; } else { now++; i--; } } ans = min(ans, now + 1); } while (next_permutation(A.begin(), A.end())); if (ans == M + 1) ans = -1; cout << ans << endl; }