N, M = map(int, input().split()) A = list(map(int, input().split())) S = list(map(int, input().split())) T = 0 X = 0 for s in S: T |= 1 << s while S: U = 0 for s in S: U |= T << s S = [] for i in range(2 * N + 1): if (X >> i) & 1: continue if not (U >> i) & 1: continue X |= 1 << i if (T >> A[i]) & 1: continue T |= 1 << A[i] S.append(A[i]) print(sum(1 & (T >> i) for i in range(2 * N + 1)))