#include <bits/stdc++.h>
using namespace std;
int n;
int v[(1 << 22)], dp[(1 << 22)];
bool vis[(1 << 22)];
int tap(int x) {
  if (vis[x]) return dp[x] = x;
  if (dp[x]) return dp[x];
  for (int i = 0; i < 22; i++)
    if (x & (1 << i) && tap(x ^ (1 << i)) != -1)
      return dp[x] = tap(x ^ (1 << i));
  return dp[x] = -1;
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", &v[i]), vis[v[i]] = 1;
  for (int i = 0; i < n; i++) printf("%d ", tap(v[i] ^ ((1 << 22) - 1)));
}
