#include <bits/stdc++.h>
using namespace std;
int vis[(1 << 22)];
void dfs(int x, int valor) {
  queue<int> q;
  q.push(x);
  vis[x] = valor;
  while (!q.empty()) {
    x = q.front();
    q.pop();
    for (int i = 0; i < 22; ++i)
      if ((x & (1 << i)) && vis[x - (1 << i)] == -1) {
        q.push(x - (1 << i));
        vis[x - (1 << i)] = valor;
      }
  }
}
int a[1000005];
int main() {
  memset(vis, -1, sizeof vis);
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
    dfs((1 << 22) - 1 - a[i], a[i]);
  }
  for (int i = 0; i < n; ++i) printf("%d ", vis[a[i]]);
  return 0;
}
