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

string memo[70][70];
bool Compare(string s1, string s2){
	//s1>s2
	if(s1.length()>s2.length())return true;
	else if(s1.length()<s2.length())return false;
	else{
		for(int i=0;i<s1.length();i++){
			if(s1[i]>s2[i])return true;
			else if(s1[i]<s2[i])return false;
		}
	}
	return false;
}

int main(){
	int w,h;
	int dy[2]={-1,0};
	int dx[2]={0,-1};
	while(cin>>w>>h && (w||h) ){
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				char ch;	cin>>ch;
				if(isdigit(ch)){
					memo[i][j]=ch;
				}else{
					memo[i][j]="*";
				}
			}
		}

		for(int y=h-1;y>=0;y--){
			for(int x=w-1;x>=0;x--){
				if(memo[y][x]=="*")continue;

				for(int i=0;i<2;i++){
					int nY=y+dy[i], nX=x+dx[i];
					if(nY<0||nX<0||nY>=h||nX>=w)continue;
					else if(memo[nY][nX]=="*")continue;

					string now=memo[nY][nX];
					string tmp=now[0]+memo[y][x];
					if(Compare(tmp,now)){
						memo[nY][nX]=tmp;
					}
				}
			}
		}

		string ans="0";
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				if(memo[i][j][0]=='0' || memo[i][j]=="*")continue;
				//cout<<memo[i][j]<<" ";

				if(Compare(memo[i][j],ans)){
					ans=memo[i][j];
					//cout<<memo[i][j]<<" ";
				}

			}
		}
		cout<<ans<<endl;

	}

	return 0;
}

