N,F = map(int, input().split()) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) now = 1 for a,b,c in zip(A,B,C): now = (now << a) | (now << b) | (now << c) #print(now) print(now.bit_count())