#include <bits/stdc++.h>
using namespace std;
struct cww {
  cww() {
    ios::sync_with_stdio(false);
    cin.tie(0);
  }
} init;
template <typename T>
void chmin(T &a, T b) {
  a = min(a, b);
}
template <typename T>
void chmax(T &a, T b) {
  a = max(a, b);
}
template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
  for (auto &it : v) is >> it;
  return is;
}
int main() {
  int n;
  cin >> n;
  vector<int> y(n);
  vector<int> x(n);
  cin >> y;
  int can = 0, cannot = 0;
  auto check = [&](int m) {
    set<int> s;
    for (int i = 0; i < n; i++) {
      int now = y[i];
      while (now > m || s.count(now)) now >>= 1;
      if (now == 0) return false;
      s.insert(now);
      x[i] = now;
    }
    return true;
  };
  for (auto &it : y) chmax(can, it);
  while (abs(can - cannot) > 1) {
    const int mid = (can + cannot) / 2;
    if (check(mid))
      can = mid;
    else
      cannot = mid;
  }
  check(can);
  for (int i = 0; i < n; i++) cout << (!i) + " " << x[i];
  cout << endl;
  return 0;
}
