N = int(input()) S = list(map(int,input().split())) T = list(map(int,input().split())) X = [-1] * N Y = [-1] * N X1 = [] Y1 = [] for i in range(N): if S[i] == 0: X[i] = 0 elif S[i] == 2: X[i] = N for j in range(N): if Y[j] == -1: Y[j] = 1 elif Y[j] < N: Y[j] += 1 else: X1.append(i) if T[i] == 0: Y[i] = 0 elif T[i] == 2: Y[i] = N for j in range(N): if X[j] == -1: X[j] = 1 elif X[j] < N: X[j] += 1 else: Y1.append(i) i = 0 for x in X1: if X[x] == -1: X[x] = 1 if -1 in Y: Y[Y.index(-1)] = 1 else: while i < N and (Y[i] == 0 or Y[i] == N): i += 1 if i < N: Y[i] += 1 i = 0 for y in Y1: if Y[y] == -1: Y[y] = 1 if -1 in X: X[X.index(-1)] = 1 else: while i < N and (X[i] == 0 or X[i] == N): i += 1 if i < N: X[i] += 1 print(sum(X))