#include <bits/stdc++.h>
using namespace std;

char tmp[72][72];
int flg[72][72];
string score[72][72];
void score_cl(){
	for(int i=0;i<5184;i++)score[i/72][i%72]="";
}
string ans;
void in(int w,int h){
	for(int i=0;i<5184;i++)flg[i/72][i%72]=0;
	ans="";
	score_cl();
	for(int i=0;i<5184;i++)tmp[i/72][i%72]='#';
	for(int i=1;i<=h;i++){
		for(int j=1;j<=w;j++){
			cin>>tmp[j][i];
		}
	}
}

int com(string a,string b){
	if(a.size()>b.size())return 1;
	if(a.size()<b.size())return 0;
	if(a==b)return 2;
	for(int i=0;i<a.size();i++){
		if(a[i]>b[i])return 1;
		if(a[i]<b[i])return 0;
	}
}



int main(){
	int w,h;
	while(cin>>w>>h,w){
		in(w,h);
		for(int j=1;j<=w;j++){
			for(int i=1;i<=h;i++){
				if('1'<=tmp[j][i] && tmp[j][i]<='9' && flg[j][i]==0){
					score_cl();
					queue<int>X,Y;
					X.push(j);Y.push(i);
					while(!X.empty()){
						int x=X.front();X.pop();
						int y=Y.front();Y.pop();
						score[x][y]+=tmp[x][y];
						flg[x][y]=1;
						if(w-x+h-y+score[x][y].size()<ans.size())continue;
						if(com(score[x][y],ans))ans=score[x][y];
						if('0'<=tmp[x+1][y] && tmp[x+1][y]<='9' && com(score[x][y],score[x+1][y])){
							if(score[x+1][y]==""){
								X.push(x+1);
								Y.push(y);
							}
							score[x+1][y]=score[x][y];
						}
						if('0'<=tmp[x][y+1] && tmp[x][y+1]<='9' && com(score[x][y],score[x][y+1])){
							if(score[x][y+1]==""){
								X.push(x);
								Y.push(y+1);
							}
							score[x][y+1]=score[x][y];
						}
					}
				}
			}
		}
		cout<<ans<<endl;
	}
	
	return 0;
}
