n = int(input()) a = int(input()) b = list(map(int, input().split())) c = int(input()) d = list(map(int, input().split())) # Sort A's cards in descending order a_sorted = sorted(b, reverse=True) # Sort C's cards in descending order and move the maximum to the end if not d: c_sorted = [] else: c_sorted = sorted(d, reverse=True) max_c = c_sorted[0] c_sorted.remove(max_c) c_sorted.append(max_c) a_len = len(a_sorted) c_len = len(c_sorted) count = 0 for k in range(n): i = k % a_len j = k % c_len if a_sorted[i] > c_sorted[j]: count += 1 print(count)