#include <bits/stdc++.h>
using namespace std;
int a[1005];
int b[1005];
int main() {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) cin >> b[i];
  long long res = 0;
  for (int i = 0; i < n; i++) {
    long long ans1 = a[i], ans2 = b[i];
    for (int j = i; j < n; j++) {
      ans1 |= a[j];
      ans2 |= b[j];
      res = max(res, ans1 + ans2);
    }
  }
  cout << res << endl;
  return 0;
}
