#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
int n, S;
int a[N], dp[1 << 23];
int main() {
  S = (1 << 22) - 1;
  scanf("%d", &n);
  memset(dp, -1, sizeof(dp));
  for (register int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    dp[S ^ a[i]] = a[i];
  }
  for (register int p = S; p >= 0; --p)
    if (dp[p] == -1) {
      for (register int i = 0; i <= 22; ++i)
        if (~dp[p | (1 << i)]) {
          dp[p] = dp[p | (1 << i)];
          break;
        }
    }
  for (register int i = 1; i <= n; ++i) printf("%d ", dp[a[i]]);
  return 0;
}
