#include <bits/stdc++.h>
using namespace std;
const int MAX_H=80;
const int dx[2]={1,0},dy[2]={0,1};

int W,H; string ans;
string C[MAX_H];
string dp[MAX_H][MAX_H];

string comp(string a,string b){
    if (a.size()<b.size()) return b;
    if (a.size()>b.size()) return a;
    return (a<b?b:a);
}

void solve(){
    ans="";
    for (int i=0;i<H;++i){
        for (int j=0;j<W;++j){
            dp[i][j]="";
            if (9<C[i][j]-'0') continue;
            string ret="";
            if (0<=i-1) ret=comp(ret,dp[i-1][j]);
            if (0<=j-1) ret=comp(ret,dp[i][j-1]);
            if (C[i][j]=='0'&&ret=="") continue;
            dp[i][j]=ret+C[i][j];
            ans=comp(ans,dp[i][j]);
        }
    }
    cout << ans << '\n';
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(cin >> W >> H,W){
        for (int i=0;i<H;++i) cin >> C[i];
        solve();
    }
}
