#include <bits/stdc++.h>
#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
const int maxn = (int)1e5 + 7;
int a[105];
int b[105];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  sort(a + 1, a + n + 1);
  int tot = unique(a + 1, a + n + 1) - a - 1;
  int bound = (1 << 30) - 1;
  for (register int i = 0; i <= bound; i++) {
    register int num = __builtin_popcount(i ^ a[1]);
    for (register int j = 2; j <= tot; j++) {
      if (__builtin_popcount(i ^ a[j]) != num) {
        num = -1;
        break;
      }
    }
    if (num != -1) {
      printf("%d\n", i);
      return 0;
    }
  }
  printf("-1\n");
  return 0;
}
