#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<(n);i++)
#define loop(i,a,n) for(i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;

string large(string s, string t){
    string ss = "", tt = "";
    int i = 0;
    while(i<s.size() && s[i]=='0')i++;
    while(i<s.size()){
        ss += s[i];
        i++;
    }
    i = 0;
    while(i<t.size() && t[i]=='0')i++;
    while(i<t.size()){
        tt += t[i];
        i++;
    }
    if(ss.size() == tt.size()){
        if(ss>tt) return ss;
        else return tt;
    }else if(ss.size() > tt.size()){
        return ss;
    }else{
        return tt;
    }
}

int main(void) {
    int i,j;
    int h, w;
    while(cin >> w >> h, h+w){
        vs s(h);
        rep(i,h) cin >> s[i];
        vector<vs> dp(h+1,vs(w+1));
        rep(i,h)rep(j,w)if(s[i][j]>='0' && s[i][j]<='9'){
            dp[i+1][j] = large(dp[i+1][j], dp[i][j]+s[i][j]);
            dp[i][j+1] = large(dp[i][j+1], dp[i][j]+s[i][j]);
        }
        string ans="";
        rep(i,h+1)rep(j,w+1)ans = large(ans, dp[i][j]);
        cout << ans << endl;
    }
}

