#include <bits/stdc++.h>
using namespace std;
long long MOD = 1e9 + 7;
void solve() {
  long long n, p;
  cin >> n >> p;
  vector<long long> k(n), cnt(1e6 + 1), dif, f(1e6 + 1);
  for (long long i = 0; i < n; i++) {
    cin >> k[i];
    cnt[k[i]]++;
  }
  sort(k.begin(), k.end());
  for (long long i = 0; i < k.size(); i++) {
    if (i == 0 || k[i - 1] != k[i]) dif.push_back(k[i]);
  }
  long long need = 0;
  for (long long i = dif.size() - 1; i >= 0; i--) {
    if (cnt[dif[i]] % 2 == 0 && !need) continue;
    if (cnt[dif[i]] * pow(p, dif[i]) >= need) {
      need = 0;
      cnt[dif[i]] -= need / pow(p, dif[i]);
    } else {
      need -= cnt[dif[i]] * pow(p, dif[i]);
      cnt[dif[i]] = 0;
    }
    if (cnt[dif[i]] % 2) need = pow(p, dif[i]);
  }
  cout << need % MOD << "\n";
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie();
  cout.tie();
  long long n;
  cin >> n;
  long long c = 60;
  vector<long long> v(n), cnt_in(c), cnt_out(c), in(n);
  vector<vector<long long> > Bits(n);
  for (long long i = 0; i < n; i++) {
    cin >> v[i];
  }
  sort(v.begin(), v.end());
  for (long long i = 0; i < n; i++) {
    long long x = v[i];
    vector<long long> bits;
    while (x > 0) {
      bits.push_back(x % 2);
      x /= 2;
    }
    reverse(bits.begin(), bits.end());
    Bits[i] = bits;
    for (long long i = 0; i < bits.size(); i++) cnt_out[i] += bits[i];
  }
  long long k = 0;
  if (n <= 3) {
    for (auto x : v) k |= x;
    cout << k;
    return 0;
  }
  for (long long z = 0; z < n; z++)
    for (long long i = 0; i < n; i++) {
      for (long long j = 0; j < n; j++) {
        if (i != j && i != z && z != j) k = max(k, v[i] | v[j] | v[z]);
      }
    }
  cout << k;
}
