#include<iostream>
#include<string>
#include<vector>
#include<cstdio>
#include<sstream>
#include<algorithm>
#include<cmath>
#include<map>
#include<functional>
#include<queue>
#include<stack>
#include<set>
using namespace std;
 char ta[100][100];
 
 string dp[100][100];
 bool ok(char n){
 	for(int i=0;i<10;i++)if(i+'0'==n)return 1;
 	return 0;
 }
 string maa(string a,string b){
 	while(a[0]=='0')a.erase(a.begin());
 	while(b[0]=='0')b.erase(b.begin());
 	if(a.size()>b.size())return a;
 	if(a.size()<b.size())return b;
 	for(int i=0;i<a.size();i++){
 		if(a[i]-'0'>b[i]-'0')return a;
 		else if(a[i]-'0'<b[i]-'0')return b;
 	}
 	return a;
 }
 
int main(){
	int h,w;
	string a,b;
	//cin>>a>>b;cout<<maa(a,b);
	while(cin>>w>>h,w+h){
	for(int i=0;i<h;i++)cin>>ta[i];
	for(int i=0;i<h;i++)for(int j=0;j<w;j++)if(ok(ta[i][j]))dp[i][j]=ta[i][j]; 
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			if(! ok(ta[i][j]))continue;
			string tmpa="",tmpb="";
			if(i>=1)tmpa=dp[i-1][j];
			if(j>=1)tmpb=dp[i][j-1];
			dp[i][j]=maa(tmpa,tmpb);
			//if(dp[i][j]=="0")dp[i][j]="";
			dp[i][j].push_back(ta[i][j]);
			//if(i&&j)cout<<i<<" "<<j<<" "<<dp[i-1][j]<<" "<<dp[i][j-1]<<" "<<min(dp[i-1][j],dp[i][j-1])<<endl;
		}
	}
	string ans;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
		//(dp[i][j].empty())? cout<<"N " : cout<<dp[i][j]<<" " ;
		ans=maa(ans,dp[i][j]);
		}
	}
	cout<<ans<<endl;
	for(int i=0;i<100;i++)for(int j=0;j<100;j++)dp[i][j]="",ta[i][j]=' ';
	}
	return 0;
}