#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000011;
const int full = (1 << 22) - 1;
int dp[full] = {-1}, a[maxn];
int main() {
  int n;
  cin >> n;
  memset(dp, -1, sizeof dp);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    dp[full ^ a[i]] = a[i];
  }
  for (int i = full - 1; i >= 0; --i)
    if (~dp[i]) {
      for (int j = 0; j < 22; ++j)
        if (i & (1 << j)) {
          dp[i ^ (1 << j)] = dp[i];
        }
    }
  cout << dp[a[0]];
  for (int i = 1; i < n; ++i) {
    cout << " " << dp[a[i]];
  }
  return 0;
}
