#include <bits/stdc++.h>
const int MN = 1e6 + 5;
const int U = 1 << 22;
int n, a[MN], f[U], mina = 0x3f3f3f3f;
int main() {
  scanf("%d", &n);
  memset(f, -1, sizeof(f));
  for (register int i = 1; i <= n; ++i)
    scanf("%d", &a[i]),
        f[a[i] ^ (U - 1)] = a[i], mina = ((mina) < (a[i]) ? (mina) : (a[i]));
  for (register int s = U - 1; s >= mina; --s) {
    if (~f[s]) continue;
    for (register int i = 0; f[s] < 0 && i < 22; ++i)
      if (~f[s | (1 << i)]) f[s] = f[s | (1 << i)];
  }
  for (register int i = 1; i <= n; ++i) printf("%d ", f[a[i]]);
  return 0;
}
