N = int(input()) M1 = int(input()) Am = list(map(int, input().split())) M2 = int(input()) Bm = list(map(int, input().split())) ts = set([i for i in range(1, N+1)]) last = 0 for m in range(M1): t = last + Am[m] last = t if t in ts: ts.remove(t) last = 0 for m in range(M2): t = last + Bm[m] last = t if t in ts: ts.remove(t) print(len(ts))