import java.util.*; import java.io.*; public class Main { static int n; static int[] toys; static int m; static int[] boxes; static final int MAX = 20; static int[][][] dp; public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); n = Integer.parseInt(br.readLine()); toys = new int[n]; String[] first = br.readLine().split(" ", n); for (int i = 0; i < n; i++) { toys[i] = Integer.parseInt(first[i]); } m = Integer.parseInt(br.readLine()); boxes = new int[m]; String[] second = br.readLine().split(" ", m); for (int i = 0; i < m; i++) { boxes[i] = Integer.parseInt(second[i]); } Arrays.sort(boxes); dp = new int[m][MAX + 1][1 << n]; int value = dfw(m - 1, boxes[m - 1], (1 << n) - 1) + 1; if (value > m) { System.out.println(-1); } else { System.out.println(value); } } static int dfw(int b, int size, int key) { if (b < 0) { return Integer.MAX_VALUE / 10; } if (key == 0) { return 0; } if (dp[b][size][key] != 0) { return dp[b][size][key]; } int min = Integer.MAX_VALUE; int count = 0; for (int i = 0; i < n; i++) { int x = 1 << i; if ((x & key) == 0) { continue; } if (toys[i] > size) { continue; } count++; min = Math.min(min, dfw(b, size - toys[i], key ^ x)); } if (count == 0) { if (b < 1) { return Integer.MAX_VALUE / 10; } min = dfw(b - 1, boxes[b - 1], key) + 1; } dp[b][size][key] = min; return min; } }