using System; using static System.Console; using System.Linq; using System.Collections.Generic; class Program { static int NN => int.Parse(ReadLine()); static int[] NList => ReadLine().Split().Select(int.Parse).ToArray(); static string[] SList(int n) => Enumerable.Repeat(0, n).Select(_ => ReadLine()).ToArray(); static void Main() { Solve(); } static void Solve() { var n = NN; var a = NList; var ordlist = new List(); var ordcnt = 0; var ones = 0; foreach (var ai in a) { var cnt = Bits(ai); if (cnt > 1) { ordlist.Add(ai); ordcnt += cnt; } else { ++ones; } } if (ordcnt + ones >= 16) { WriteLine(32768); return; } var res = 0; Permutate(ordlist.Count, list => { var sub = 0; for (var i = 0; i < list.Length; ++i) { var tmp = sub; var li = ordlist[list[i]]; for (var j = 0; j < 16; ++j) { sub = Math.Max(sub, tmp | li); li = Shift(li); } } res = Math.Max(res, sub); }); for (var i = 0; i < ones; ++i) { var tmp = res; var li = 1; for (var j = 0; j < 16; ++j) { res = Math.Max(res, tmp | li); li = Shift(li); } } WriteLine(res); } static void Permutate(int n, Action action) { var seed = new int[n]; for (var i = 0; i < n; ++i) seed[i] = i; var used = new bool[n]; var perm = new int[n]; Permutate(0, seed, perm, used, action); } static void Permutate(int pos, int[] seed, int[] perm, bool[] used, Action action) { if (pos == used.Length) action(perm); for (var i = 0; i < used.Length; ++i) { if (used[i]) continue; perm[pos] = seed[i]; used[i] = true; Permutate(pos + 1, seed, perm, used, action); used[i] = false; } } static int Shift(int a) { return a / 2 + (1 << 15) * (a % 2); } static int Bits(int a) { var res = 0; while (a > 0) { if (a % 2 == 1) ++res; a >>= 1; } return res; } }