#include <bits/stdc++.h>
using namespace std;
int n;
queue<int> q;
int Par[1 << 22];
int A[1000005];
int Set(int N, int pos) { return N = N | (1 << pos); }
void BFS() {
  memset(Par, -1, sizeof(Par));
  for (int i = 1; i <= n; i++) {
    if (Par[A[i]] != -1) continue;
    q.push(A[i]);
    Par[A[i]] = A[i];
  }
  while (!q.empty()) {
    int v = q.front();
    q.pop();
    for (int i = 0; i < 22; i++) {
      int w = Set(v, i);
      if (Par[w] != -1) continue;
      Par[w] = Par[v];
      q.push(w);
    }
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &A[i]);
  BFS();
  int mask = (1 << 22) - 1;
  for (int i = 1; i <= n; i++) printf("%d ", Par[A[i] ^ mask]);
}
