#include <bits/stdc++.h>
int const inf = (1 << 22) - 1;
using namespace std;
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
  return x * f;
}
int n, a[1000010], f[4200000];
int main() {
  memset(f, -1, sizeof(f));
  n = read();
  for (int i = 1; i <= n; ++i) {
    a[i] = read();
    f[(~a[i]) & inf] = a[i];
  }
  for (int s = inf; s >= 0; --s) {
    if (f[s] != -1) continue;
    for (int j = 1; j <= 22; ++j)
      if (!(s & (1 << j - 1)))
        if ((f[s] = f[s | (1 << j - 1)]) != -1) break;
  }
  for (int i = 1; i <= n - 1; ++i) printf("%d ", f[a[i]]);
  printf("%d\n", f[a[n]]);
  return 0;
}
