#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
const int M = 5e4 + 5, INF = 0x3f3f3f3f, mod = 1000007;
struct TRIE {
  int ch[M * 30][2];
  int cnt[M * 30];
  int L, root;
  int newnode() {
    ch[L][0] = ch[L][1] = -1;
    cnt[L] = 0;
    return L++;
  }
  void init() {
    L = 0;
    root = newnode();
  }
  void insert(int x) {
    int now = root;
    int ok = 0;
    for (int j = 30; j >= 0; j--) {
      int t = (x >> j) & 1;
      if (!ok && !t) continue;
      ok = 1;
      if (ch[now][t] == -1) {
        ch[now][t] = newnode();
        now = ch[now][t];
      } else
        now = ch[now][t];
    }
    cnt[now]++;
  }
  void dfs(int root, int now, int mid, vector<int>& tmp) {
    if (ch[root][0] != -1)
      dfs(ch[root][0], now * 2, mid, tmp), cnt[root] += cnt[ch[root][0]];
    if (ch[root][1] != -1)
      dfs(ch[root][1], now * 2 + 1, mid, tmp), cnt[root] += cnt[ch[root][1]];
    if (now && now <= mid && cnt[root] > 0) {
      cnt[root]--, tmp.push_back(now);
    }
  }
  bool solve(int mid, vector<int>& tmp) {
    dfs(root, 0, mid, tmp);
    return cnt[root] <= 0;
  }
} trie;
vector<int> ans;
vector<int> tmp;
int A[M];
int n;
bool check(int mid) {
  trie.init();
  tmp.clear();
  for (int j = 1; j <= n; j++) {
    trie.insert(A[j]);
  }
  return trie.solve(mid, tmp);
}
int main() {
  scanf("%d", &n);
  for (int j = 1; j <= n; j++) scanf("%d", &A[j]);
  int l = 0, r = 1e9;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (check(mid)) {
      ans = tmp;
      r = mid - 1;
    } else
      l = mid + 1;
  }
  for (int j = 0; j < ans.size(); j++) printf("%d ", ans[j]);
  printf("\n");
  return 0;
}
