import itertools def main(): import sys input = sys.stdin.read().split() ptr = 0 N = int(input[ptr]) ptr +=1 A = int(input[ptr]) ptr +=1 B = list(map(int, input[ptr:ptr+A])) ptr +=A C = int(input[ptr]) ptr +=1 D = list(map(int, input[ptr:ptr+C])) ptr +=C max_victory = 0 # 生成所有可能的A的排列顺序 A_perms = list(itertools.permutations(B)) # 生成所有可能的C的排列顺序 C_perms = list(itertools.permutations(D)) for a_order in A_perms: for c_order in C_perms: i = 0 j = 0 victory = 0 for _ in range(N): a = a_order[i % A] c = c_order[j % C] if a > c: victory +=1 i +=1 j +=1 if victory > max_victory: max_victory = victory if max_victory == N: break if max_victory == N: break print(max_victory) if __name__ == "__main__": main()