#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(NULL);
  cout.tie(NULL);
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> a(n), f(1 << 22, -1);
  int m = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    f[a[i]] = a[i];
  }
  int d = 22;
  for (int i = 0; i < d; i++)
    for (int j = 0; j < (1 << d); j++)
      if (j & (1 << i) && f[j ^ (1 << i)] != -1) f[j] = f[j ^ (1 << i)];
  int x = (1 << d) - 1;
  for (int i = 0; i < n; i++) cout << f[a[i] ^ x] << " ";
  cout << "\n";
  return 0;
}
