#!/usr/bin/env python3 n = int(input()) a = int(input()) b = list(map(int,input().split())) c = int(input()) d = list(map(int,input().split())) ans = 0 xs, ys = [], [] for _ in range(n): if not len(xs): xs = list(sorted(b)) if not len(ys): ys = list(sorted(d)) for x in xs: zs = list(filter(lambda y: y < x, ys)) if len(zs): xs.remove(x) ys.remove(min(zs)) ans += 1 break else: xs.remove(xs[0]) ys.remove(ys[-1]) print(ans)