import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNextInt()) {
            int n = sc.nextInt();
            Map<String, Boolean> isVisited = new HashMap<>();
            for (int i = 0; i < n; i++) {
                String s = sc.next();
                isVisited.put(s, false);
            }
            int m = sc.nextInt();
            int ans = 0;
            for (int i = 0; i < m; i++) {
                String s = sc.next();
                if (!isVisited.containsKey(s)) continue;
                isVisited.put(s, true);
                boolean flag = true;
                for (boolean b : isVisited.values()) {
                    if (!b) {
                        flag = false;
                        break;
                    }
                }
                if (flag) {
                    isVisited.replaceAll((k, v) -> false);
                    isVisited.put(s, true);
                    ans++;
                }
            }
            System.out.println(ans == m ? -1 : ans);
        }
    }
}