#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
typedef pair<int, string> i_S;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
int H, W;
string field[72];
i_S dp[72][72];


int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(true) {
        cin >> W >> H;
        if(W == 0) break;
        for(int h = 1; h <= H; h++) {
            cin >> field[h];
            field[h] = "&" + field[h];
        }
        for(int h = 1; h <= 71; h++) {
            for(int w = 1; w <= 71; w++) {
                dp[h][w] = {0, ""};
            }
        }
        i_S ans = {0, ""};
        for(int h = H; h >= 1; h--) {
            for(int w = W; w >= 1; w--) {
                if(field[h][w] <= 'Z' && field[h][w] >= 'A') continue;
                i_S now = max(dp[h+1][w], dp[h][w+1]);
                now.first++;
                now.second = field[h][w] + now.second;
                if(now.second[0] != '0') ans = max(ans, now);
                dp[h][w] = now;
            }
        }
        cout << ans.second << endl;
    }
    return 0;
}
