#include "bits/stdc++.h"
#define int long long
using namespace std;

signed main () {
	int n; cin >> n;
	vector <int> v(n);
	multiset<int> st;
	set <int> test;
	map<int,set<int>> mp;
	for (int i = 0; i < n; i++){
		cin >> v[i];
		st.insert(v[i]);
		test.insert(v[i]);
	}
	for (auto to : test){
		mp[st.count(to)].insert(to);
	}
	for (auto &to : mp){
		to.second.insert(1e18);
	}
	pair<int,int> mn = {1e9, 0};
	for (auto to : mp){
		//cout << to.first <<" : ";
		for (auto u : to.second){
			//cout << u <<" ";
			if(mn.first > u){
				mn = {u, to.first};
			}
		}
		//cout << endl;
	}
	vector <int> cur = {0};
	//cout << mn.second << endl;
	for (int i = mn.second; i >= 1; i--){
		vector <int> o;
		if(mp[i].size() == 0){
			cout << -1 << endl;
			return 0;
		}
		for (int j = 0; j < cur.size(); j++){
			int res = *mp[i].upper_bound(cur[j]);
			if(res == 1e18){
				cout << -1 << endl;
				return 0;
			}
			if(cur[j] != 0)
				o.push_back(cur[j]);
			o.push_back(res);
			mp[i].erase(mp[i].find(res));
		}
		cur = o;
	}
	for (auto to : mp){
		if(to.second.size() > 1){
			cout << -1 << endl;
			return 0;
		}
	}
	for (auto to : cur){
		cout << to <<" ";
	}
	return 0;
}