N = int(input()) X = list(map(int, input().split())) A = list(map(int, input().split())) SUM = sum(A) cum = [0] cumXOR = [0] for i in range(N): cum.append(cum[-1]+A[i]) cumXOR.append(cumXOR[-1]^A[i]) def rangeSUM(l, r): return cum[r+1]-cum[l] ans = 10**18 for i in range(N): for j in range(i, N): xor = cumXOR[j+1]^cumXOR[i] cost = X[j]-X[i] sumA = 0 if 1 <= i: sumA += rangeSUM(0, i-1) if j < N-1: sumA += rangeSUM(j+1, N-1) ans = min(ans, xor+cost+sumA) print(ans)