#include <bits/stdc++.h>
   
#define int long long
#define ld long double

using namespace std;
 
main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int n;
	cin >> n;
	map<int , int> us;
    int gg = 1 , h = 0;
    while(gg < n){
        gg *= 2;
    	h ++;
    }
    bool ok = true;
    int a[n + 17];
    for(int i = 1;i <= n; ++ i){
    	cin >> a[i];
    	us[a[i]] ++;
    	if(us[a[i]] > h){
    		cout << -1;
    		return 0;
    	}
    }
	vector<int> v[30];
    for(int i = 1;i <= n; ++ i){
    	v[us[a[i]]].push_back(a[i]);
    	us[a[i]] = 0;
    }
    vector<int> q , p;
    if(v[h].empty()) {
    	cout << -1;
    	return 0;
    }
    p.push_back(v[h][0]);
    map<int, int> b;
    set<int> s;
    for(int i = h; i >= 2; -- i){
    	for(auto to : v[i]){
    		 us[to] = 1;
    		 s.insert(to);
    		 q.push_back(to);
    	}
    	for(auto to : v[i - 1]){
    		p.push_back(to);
    	}
    	sort(p.begin() , p.end());
    	if(p.size() != powl(2 , h - i + 1) or q.size() != powl(2 , h - i)){
    		 cout << -1;
    		 return 0;
    	}
    	int l = 0;
    	//cout << s.size() << ' ';
    	for(auto to : s){
    	  while(l < p.size() and us[p[l]] == 1){
    	  	 l ++;
    	  }
    	  //cout << l << ' ';
    	  b[to] = p[l];
    	  us[p[l]] = 1;
    	}
    	for(int j = 0;j < q.size(); ++ j){
    	   if(min(q[j] , b[q[j]]) != q[j]){
    	   	cout << -1;
    	   	return 0;
    	   }
    	}
    }
    for(auto to : q){
    	cout << to << " " << b[to] << " ";
    }
}
