
#include <list>
#include <iostream>

using namespace std;

//this would be much better using iterators (think about it for the next lesson)
template<typename T>
list<T> list_merge(list<T> &l1, list<T> &l2) {
	list<T> tmp;
	while (!l1.empty() && !l2.empty()) {
		if (l1.front() <= l2.front()) {
			tmp.push_back(l1.front());
			l1.pop_front();
		}
		else {
			tmp.push_back(l2.front());
			l2.pop_front();
		}
	}
	tmp.insert(tmp.end(), l1.begin(), l1.end());
	tmp.insert(tmp.end(), l2.begin(), l2.end());
	return tmp;
}

int main()
{
	list<int> l;
	for (int i = 0; i < 10; i++) {
		int tmp;
		cin >> tmp;
		l.push_back(tmp);
	}
	list<list<int>> res;
	
	while (!l.empty()) {
		res.push_front(list<int>());
		res.front().push_front(l.front());
		l.pop_front();
	}

	while (res.size() > 1) {
		list <int> first = res.front();
		res.pop_front();
		list<int> second = res.front();
		res.pop_front();
		res.push_back(list_merge(first, second));
	}

	if(!res.empty()) l = res.front();

	for (auto &i : l) {
		cout << i << endl;
	}
    return 0;
}

