#include <bits/stdc++.h>
using namespace std;
const int nax = 1e6 + 200;
const int N = 22;
const int L = (1 << 22) - 1;
int a[nax];
int dp[(1 << N)];
int A[1 << N];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cout << setprecision(20) << fixed;
  int n;
  cin >> n;
  for (int i = 0; i < (int)n; ++i) cin >> a[i];
  for (int i = 0; i < (int)n; ++i) {
    A[a[i]] = a[i];
  }
  for (int mask = 0; mask < (1 << N); ++mask) {
    dp[mask] = A[mask];
  }
  for (int mask = 0; mask < (1 << N); ++mask) {
    if (dp[mask] == 0) continue;
    for (int i = 0; i < N; ++i) {
      if ((mask & (1 << i)) == 0) {
        dp[mask ^ (1 << i)] = dp[mask];
      }
    }
  }
  for (int i = 0; i < (int)n; ++i) {
    int mask = L ^ a[i];
    if (dp[mask]) {
      cout << dp[mask] << " ";
    } else {
      cout << -1 << " ";
    }
  }
  cout << '\n';
}
