#include <bits/stdc++.h>
using namespace std;
ifstream in("in.txt");
ofstream out("out.txt");
pair<long long, long long> a[100005];
long long c[33];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n, i, x = 0, j;
  cin >> n;
  for (i = 1; i <= n; ++i) {
    cin >> a[i].first;
    for (j = 0; (1 << j) <= a[i].first; ++j) {
      c[j] += bool((1 << j) & a[i].first);
    }
  }
  for (i = 0; i <= 32; ++i) {
    if (c[i] > 1) {
      x += (1 << i);
    }
  }
  for (i = 1; i <= n; ++i) {
    a[i].second = a[i].first;
    a[i].first = (a[i].first | x) - x;
  }
  sort(a + 1, a + n + 1);
  for (i = n; i >= 1; --i) {
    cout << a[i].second << " ";
  }
  return 0;
}
