#include <bits/stdc++.h>
using namespace std;
int dp[1 << 22];
int v[1 << 22];
int a[1000005];
int solve(int bitmask) {
  if (v[bitmask] != -1) {
    return v[bitmask];
  }
  if (dp[bitmask] != -1) return dp[bitmask];
  int ans = -(1 << 30);
  for (int i = 0; i < 22 && ans < 0; i++) {
    if (bitmask & (1 << i)) {
      int turn_off = (1 << i);
      ans = solve(bitmask ^ turn_off);
    }
  }
  return dp[bitmask] = ans;
}
int main() {
  int n;
  scanf("%d", &n);
  memset(dp, -1, sizeof dp);
  memset(v, -1, sizeof v);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    v[a[i]] = a[i];
  }
  for (int i = 0; i < n; i++) {
    int inv = ((1 << 22) - 1) ^ a[i];
    int ans = solve(inv);
    if (ans < -1) ans = -1;
    printf("%d ", ans);
  }
  return 0;
}
