#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi M_PI
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

string large(string s, string t){
    if (s.length() > t.length()) return s;
    if (s.length() < t.length()) return t;
    REP(i,s.length()){
        if (s[i] > t[i]) return s;
        if (s[i] < t[i]) return t;
    }
    return s;
}

int main() {
    int w, h;
    while (cin >> w >> h && w){
        vector<vector<string> > dp(h, vector<string>(w));
        REP(i,h){
            string s;
            cin >> s;
            REP(j,w){
                if (s[j] >= '0' && s[j] <= '9')
                    dp[i][j].push_back(s[j]);
            }
        }
        vector<vector<string> > a(dp);
        REP(i,h) REP(j,w) {
            if (dp[i][j] == "0" || a[i][j].empty()) continue;
            if (i < h-1)
                dp[i+1][j] = large(dp[i+1][j], dp[i][j]+a[i+1][j]);
            if (j < w-1)
                dp[i][j+1] = large(dp[i][j+1], dp[i][j]+a[i][j+1]);
        }
        string ans;
        REP(i,h) REP(j,w) {
            ans = large(ans, dp[i][j]);
        }
        cout << ans << endl;
    }
    return 0;
}