#include <bits/stdc++.h>
using namespace std;
const int MaxBit = 22;
int dp[5555555];
int a[1111111];
int n;
int Getdp(int x) {
  if (dp[x] != 0)
    return dp[x];
  else {
    int mask = 1;
    int ans = -1;
    for (int i = 0; i < MaxBit; i++) {
      if (x & mask) {
        if (Getdp(x - mask) != -1) {
          ans = Getdp(x - mask);
          break;
        }
      }
      mask <<= 1;
    }
    return dp[x] = ans;
  }
}
int main() {
  scanf("%d", &n);
  dp[0] = -1;
  for (int i = 0; i < n; i++) scanf("%d", &a[i]), dp[a[i]] = a[i];
  for (int i = 0; i < n; i++) {
    if (i) putchar(' ');
    printf("%d", Getdp(a[i] ^ ((1 << 22) - 1)));
  }
  printf("\n");
}
