#include <bits/stdc++.h>
using namespace std;
inline long long gcd(long long a, long long b) {
  return (b ? gcd(b, a % b) : a);
}
inline long long lcm(long long a, long long b) { return (a / gcd(a, b)) * b; }
const int MAXN = 50005;
vector<int> v[MAXN];
int pos[MAXN];
unordered_map<int, int> usado;
unordered_map<int, int> pertence;
set<pair<int, int> > q;
bool espreme(int i) {
  if (pos[i] == 0) return false;
  if (usado[v[i][pos[i] - 1]] && !espreme(pertence[v[i][pos[i] - 1]]))
    return false;
  usado[v[i][pos[i]]] = 0;
  q.erase(q.find(make_pair(-v[i][pos[i]], i)));
  pos[i]--;
  usado[v[i][pos[i]]] = 1;
  pertence[v[i][pos[i]]] = i;
  q.insert(make_pair(-v[i][pos[i]], i));
  return true;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) {
    int x = a[i];
    while (x) {
      v[i].push_back(x);
      x /= 2;
    }
    reverse(v[i].begin(), v[i].end());
  }
  for (int i = 0; i < n; i++) {
    usado[a[i]] = 1;
    pertence[a[i]] = i;
    pos[i] = v[i].size() - 1;
    q.insert(make_pair(-a[i], i));
  }
  while (!q.empty()) {
    int i = q.begin()->second;
    if (!espreme(i)) break;
  }
  for (int i = 0; i < n; i++) cout << v[i][pos[i]] << " ";
  cout << endl;
}
