#include <bits/stdc++.h>
#define REP(i,n,N) for(int i=n;i<N;i++)
#define p(S) cout<<S<<endl
#define ck(n,a,b) (a<=(n)&&(n)<=b)
using namespace std;

int snW,snH;
char snC[75][75];
string sndp[75][75];

string snrec(int x,int y){
	if(!ck(x,0,snW-1)||!ck(y,0,snH-1)||!ck(snC[y][x],'0','9')) return "";
	if(sndp[y][x]!="") return sndp[y][x];

	string ns1=snC[y][x]+snrec(x+1,y);
	string ns2=snC[y][x]+snrec(x,y+1);

	if(sndp[y][x].size()==ns1.size()){
		REP(k,0,(int)ns1.size()){
			if(sndp[y][x][k]==ns1[k]) continue;
			else if(sndp[y][x][k]<ns1[k])	sndp[y][x]=ns1;
			break;
		}
	}else if(sndp[y][x].size()<ns1.size()) sndp[y][x]=ns1;

	if(sndp[y][x].size()==ns2.size()){
		REP(k,0,(int)ns2.size()){
			if(sndp[y][x][k]==ns2[k]) continue;
			else if(sndp[y][x][k]<ns2[k])	sndp[y][x]=ns2;
			break;
		}
	}else if(sndp[y][x].size()<ns2.size()) sndp[y][x]=ns2;

	return sndp[y][x];
}

int main(){
	while(cin>>snW>>snH,snW){
		REP(i,0,snH){
			REP(j,0,snW){
				cin>>snC[i][j];
				sndp[i][j]="";
			}
		}
		string ans="";
		REP(i,0,snH){
			REP(j,0,snW){
				if(ck(snC[i][j],'1','9')){
					string ns=snrec(j,i);
					if(ans.size()==ns.size()){
						REP(k,0,(int)ns.size()){
							if(ans[k]==ns[k]) continue;
							else if(ans[k]<ns[k])	ans=ns;
							break;
						}
					}else if(ans.size()<ns.size()) ans=ns;
				}

			}
		}
		cout<<ans<<endl;
	}

	return 0;
}