#include <iostream>
#include <cstdio>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <cstring>
#include <functional>
#include <cmath>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define rep1(i,n) for(int i=1;i<=(n);++i)
#define all(c) (c).begin(),(c).end()
#define fs first
#define sc second
#define pb push_back
#define show(x) cout << #x << " " << x << endl
void renew(string& x,string y){
	if(x.size()<y.size()){
		x=y;
		return;
	}else if(x.size()>y.size()){
		return;
	}else{
		if(x<y) x=y;
	}
}
int main(){
	while(true){
		int W,H;
		cin>>W>>H;
		if(H==0) break;
		string s[70];
		rep(i,H) cin>>s[i];
		string dp[70][70];
		rep(i,H) rep(j,W){
			if(!isdigit(s[i][j])) continue;
			string val;
			if(s[i][j]!='0') val=string(1,s[i][j]);
			if(i!=0&&dp[i-1][j].size()>0) renew(val,dp[i-1][j]+s[i][j]);
			if(j!=0&&dp[i][j-1].size()>0) renew(val,dp[i][j-1]+s[i][j]);
			dp[i][j]=val;
		}
		string ans;
		rep(i,H) rep(j,W) renew(ans,dp[i][j]);
		cout<<ans<<endl;
	}
}