import bisect n = int(input()) a = int(input()) b = list(map(int, input().split())) c = int(input()) d = list(map(int, input().split())) b.sort() d.sort() # Calculate the number of wins per full cycle of C's cards wins_per_cycle = 0 for num in d: idx = bisect.bisect_right(b, num) if idx < len(b): wins_per_cycle += 1 # Calculate the number of full cycles and remaining matches full_cycles = n // len(d) remaining_matches = n % len(d) # Calculate wins from remaining matches remaining_wins = 0 for i in range(remaining_matches): num = d[i] idx = bisect.bisect_right(b, num) if idx < len(b): remaining_wins += 1 total_wins = full_cycles * wins_per_cycle + remaining_wins print(total_wins)