#include <bits/stdc++.h>
using namespace std;
long long btoi(string a) {
  long long ans = 0;
  for (int i = a.size() - 1; i >= 0; i--)
    if (a[i] == '1') ans += pow(2, a.size() - 1 - i);
  return ans;
}
string itob(int n) {
  string a = "";
  while (n > 0) {
    if (n % 2 == 0)
      a = "0" + a;
    else
      a = "1" + a;
    n /= 2;
  }
  return a;
}
string aorb(int n, string b) {
  string a = itob(n);
  if (a.size() > b.size()) swap(a, b);
  while (a.size() < b.size()) a = '0' + a;
  for (int i = 0; i < a.size(); i++)
    if (b[i] == '1' || a[i] == '1')
      b[i] = '1';
    else
      b[i] = '0';
  return b;
}
int main() {
  long long n, a;
  string x1 = "        ", x2 = "            ";
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a;
    x1 = aorb(a, x1);
  }
  for (int i = 0; i < n; i++) {
    cin >> a;
    x2 = aorb(a, x2);
  }
  cout << btoi(x1) + btoi(x2);
}
