#include "bits/stdc++.h" using namespace std; #define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i)) #define rep(i,j) FOR(i,0,j) #define each(x,y) for(auto &(x):(y)) #define mp make_pair #define all(x) (x).begin(),(x).end() #define debug(x) cout<<#x<<": "<<(x)< pii; typedef vector vi; typedef vector vll; int N; vector S; void solve(){ each(s, S)s += '~'; vi kk(N); string ans; while(true){ string mini = "~"; int k = -1; rep(i, N){ string sub = S[i].substr(kk[i]); if(sub < mini){ mini = sub; k = i; } } if(k == -1){ break; } else{ ans += mini[0]; kk[k]++; } } cout << ans << endl; } int main(){ while(cin >> N){ S.resize(N); rep(i, N)cin >> S[i]; solve(); } }