#include<string>
#include<iostream>
#include<cstdio>
using namespace std;
bool isbigger(string a,string b,int j) // returns true if auxillary number > max
{
int asz=j+1,bsz=b.size(),diff=bsz-asz; //asz is size of a, sim bsz
if(diff>0) while(diff--) a='0'+a;//padding0
else if(diff<0){
diff=-diff;
while(diff--) b='0'+b; //padding 0
}
if(a>b) return 1;
else return 0;
}
main(){
string a;
cin>>a;
int i,j,k,chars=0;
string aux="",max="0";
for(i=0;a[i]=='0';i++);
for(;a[i];i++){
aux="";
for(j=0;a[i+j]=='0';j++);
for(;a[i+j];j++){
if(a[i+j]>='A' && a[i+j]<='Z'){
chars++;
if(chars>1) break;
aux+='9';}
else aux+=a[i+j];
if(isbigger(aux,max,j)) max=aux;
cout<<aux<<" "<<max<<endl;
}
chars=0;
}
if(max=="") max="0";
cout<<max;
}//end of code
I2luY2x1ZGU8c3RyaW5nPgojaW5jbHVkZTxpb3N0cmVhbT4KI2luY2x1ZGU8Y3N0ZGlvPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKYm9vbCBpc2JpZ2dlcihzdHJpbmcgYSxzdHJpbmcgYixpbnQgaikgLy8gcmV0dXJucyB0cnVlIGlmIGF1eGlsbGFyeSBudW1iZXIgPiBtYXgKewppbnQgYXN6PWorMSxic3o9Yi5zaXplKCksZGlmZj1ic3otYXN6OyAvL2FzeiBpcyBzaXplIG9mIGEsIHNpbSBic3oKaWYoZGlmZj4wKSB3aGlsZShkaWZmLS0pIGE9JzAnK2E7Ly9wYWRkaW5nMAplbHNlIGlmKGRpZmY8MCl7CiAgICBkaWZmPS1kaWZmOwogICAgd2hpbGUoZGlmZi0tKSBiPScwJytiOyAvL3BhZGRpbmcgMAogICAgfQppZihhPmIpIHJldHVybiAxOwplbHNlIHJldHVybiAwOwp9CgoKbWFpbigpewoKc3RyaW5nIGE7CmNpbj4+YTsKaW50IGksaixrLGNoYXJzPTA7CnN0cmluZyBhdXg9IiIsbWF4PSIwIjsKCmZvcihpPTA7YVtpXT09JzAnO2krKyk7CmZvcig7YVtpXTtpKyspewogICBhdXg9IiI7CiAgIGZvcihqPTA7YVtpK2pdPT0nMCc7aisrKTsKICAgZm9yKDthW2kral07aisrKXsKICAgICAgICAgICAgICAgICAgICAgICAgaWYoYVtpK2pdPj0nQScgJiYgYVtpK2pdPD0nWicpewogICAgICAgICAgICAgICAgICAgICAgICBjaGFycysrOwogICAgICAgICAgICAgICAgICAgICAgICBpZihjaGFycz4xKSBicmVhazsKICAgICAgICAgICAgICAgICAgICAgICAgYXV4Kz0nOSc7fQogICAgICAgICAgICAgICAgICAgICAgICBlbHNlIGF1eCs9YVtpK2pdOwogICAgICAgICAgICAgICAgICAgICAgICBpZihpc2JpZ2dlcihhdXgsbWF4LGopKSBtYXg9YXV4OwogICAgICAgICAgICAgICAgICAgICAgICBjb3V0PDxhdXg8PCIgIjw8bWF4PDxlbmRsOwogICB9CiAgIGNoYXJzPTA7CiAgIH0KCiAgIGlmKG1heD09IiIpIG1heD0iMCI7CiAgIGNvdXQ8PG1heDsKICAgfS8vZW5kIG9mIGNvZGU=