#include <bits/stdc++.h>
using namespace std;
int vis[(1 << 22)];
void dfs(int x, int valor) {
  if (vis[x] >= 0) return;
  vis[x] = valor;
  for (int i = 0; i < 22; ++i)
    if (x & (1 << i)) dfs(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;
}
