#include<bits/stdc++.h>

using namespace std;
using ll = long long int;
#define long ll

int main(void) {
    cin.tie(0); ios::sync_with_stdio(false);

    auto f = [&](char x, const string &s) {
        string r = s;
        ll i = 150 - 1;
        while(r[i] != ' ') i--;
        r[i] = x;
        return r;
    };
    while(1) {
        ll w, h;
        cin >> w >> h;
        if(!w) break;

        vector<string> c(h);
        for(auto &l: c) cin >> l;

        vector<vector<string>> dp(h+1, vector<string>(w+1, string(150, ' ')));

        for(ll i=h-1; i>=0; i--)
        for(ll j=w-1; j>=0; j--)
            if('0' <= c[i][j] && c[i][j] <= '9')
                dp[i][j] = f(c[i][j], max(dp[i+1][j], dp[i][j+1]));

        string m = "";
        for(ll i=0; i<h; i++)
        for(ll j=0; j<w; j++) {
            ll k = 0;
            while(dp[i][j][k] == ' ' || dp[i][j][k] == '0') dp[i][j][k++] = ' ';
            m = max(m, dp[i][j]);
        }
        {
            ll i = 0;
            while(m[i] == ' ' || m[i] == '0') i++;
            for(; i<150; i++)
                cout << m[i];
            cout << endl;
        }

    }
}

