#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
string a[100005], f[100005], ans[100005];
int cur, cnt;
int main() {
char c;
while(cin>>c){
if(isupper(c))
a[++cnt] = c;
else a[cnt] += c;
}
for(int i = 1; i <= cnt; i++){
if(a[i] > f[cur])
f[++cur] = a[i];
else {
int p = lower_bound(f+1,f+cur+1,a[i]) - f;
f[p] = a[i];
ans[p] = ans[p-1]+a[i];
}
}
cout << ans[cur] << endl;
return 0;
}