#include
#define m 10000
int main()
{
int p[m],i,j,k,n;
char a[m];
while(1)
{
i=0;n=0,k=0;
while((a[i]=getchar())!='\n'&&a[i]!=EOF)
i++;
if(a[i]==EOF) break;
for(j=0;j if(a[j]!='5')
k=k*10+a[j]-'0';
else if(a[j+1]!='5')
{
p[n]=k;
k=0;
n++;
}
if(a[i-1]!='5')
{
p[n]=k;
n=n+1;
}
for(j=0;j
{
k=p[i];
p[i]=p[i+1];
p[i+1]=k;
}
/*if(a[0]!='5')
printf("%d ",p[0]);
for(j=1;j
printf("%d\n",p[n-1]);
*/
if(a[0]!='5') j=0;
else j=1;
printf("%d",p[j++]);
for(;j
printf("\n");
}
}