#include #include #include #include #define REP(i, n) for(int i=0;i<(n);i++) using namespace std; int main() { cin.tie(0); ios::sync_with_stdio(false); int N; cin >> N; vector s; REP(i, N) { string tmp; cin >> tmp; s.push_back(tmp); } string t; int minidx = 0; while (!all_of(begin(s), end(s), [](string &tmp) { return tmp.empty(); })) { char minc = CHAR_MAX; for (int i = 0; i < s.size(); ++i) { if (s[i].empty()) continue; if (s[i][0] < minc) { minidx = i; minc = s[i][0]; } else if (s[i][0] == minc) { int j = 0; while (j < s[i].size() && j < s[minidx].size() && s[i][j] == s[minidx][j]) ++j; if (j >= s[minidx].size()) { minidx = i; } else if (j < s[i].size()) { if (s[i][j] < s[minidx][j]) minidx = i; } } } t += minc; s[minidx] = s[minidx].substr(1, s[minidx].size() - 1); } cout << t << endl; return 0; }