#include <bits/stdc++.h>
using namespace std;
const int N = (1 << 22);
const int mod = 1000000007;
int n;
vector<int> a;
vector<int> dp;
vector<bool> vis;
int ulta(int x) {
  int ret = 0;
  for (int i = 0; i < 22; i++) {
    if ((x & (1 << i)) == 0) {
      ret += (1 << i);
    }
  }
  return ret;
}
void dfs(int x, int y) {
  if (vis[x]) return;
  vis[x] = true;
  dp[x] = y;
  for (int i = 0; i < 22; i++) {
    if ((x & (1 << i)) != 0) {
      dfs((x ^ (1 << i)), y);
    }
  }
}
void pre() {}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  pre();
  cin >> n;
  a.resize(n);
  dp.assign(N, -1);
  vis.assign(N, false);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    dfs(ulta(a[i]), a[i]);
  }
  for (auto i : a) {
    cout << dp[i] << " ";
  }
  cout << "\n";
}
