#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll act;
int n;
vector<pair<ll, ll>> a;
int vis[35];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n;
  a.resize(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i].second;
    int cnt = 0;
    int tmp = a[i].second;
    while (tmp > 0) {
      if (tmp % 2) vis[cnt]++;
      cnt++;
      tmp /= 2;
    }
  }
  for (int i = 0; i < 35; i++) {
    if (vis[i] == 1) {
      act += (1 << i);
    }
  }
  for (int i = 0; i < n; i++) {
    a[i].first = (a[i].second & act);
  }
  sort(a.begin(), a.end());
  for (int i = n - 1; i >= 0; i--) {
    cout << a[i].second << ' ';
  }
  return 0;
}
