#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int inf = 1e9;
const int mod = 1e9 + 7;
const int maxn = 5e5 + 10;
int n;
int a[1010], b[1010];
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (int i = 1; i <= n; i++) {
    cin >> b[i];
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    int r1 = 0, r2 = 0;
    for (int j = i; j <= n; j++) {
      r1 |= a[j];
      r2 |= b[j];
      ans = max(r1 + r2, ans);
    }
  }
  cout << ans << endl;
  return 0;
}
