#include<bits/stdc++.h>
using namespace std;
const int N=1000005;
int cnt,next[N],id[N];
string s[N],st,z[N];
void add(string st,int p)
{
if(st>s[cnt])
{
s[++cnt]=st;
id[cnt]=p;
next[p]=id[cnt-1];
return;
}
int l=1,r=cnt;
while(l<r)
{
int mid=(l+r)/2;
if(s[mid]<=st)l=mid+1;
else r=mid;
}
s[r]=st;
id[r]=p;
next[p]=id[r-1];
}
void print(int p)
{
if(!p)return;
print(next[p]);
cout<<z[p];
}
int main()
{
cin>>st;
string x="";
int cal=0;
for(int i=0;i<st.size();i++)
{
if(st[i]>='A'&&st[i]<='Z')z[++cal]=st[i];
else z[cal]+=st[i];
}
for(int i=1;i<=cal;i++)add(z[i],i);
print(id[cnt]);
return 0;
}