#include <bits/stdc++.h>
using namespace std;
int main() {
  int num;
  long long a[1005];
  long long b[1005];
  while (cin >> num) {
    long long aa = 0;
    long long bb = 0;
    for (int i = 0; i < num; i++) {
      cin >> a[i];
      aa = aa | a[i];
    }
    for (int i = 0; i < num; i++) {
      cin >> b[i];
      bb = bb | b[i];
    }
    cout << aa + bb << endl;
  }
}
