#include <iostream>
#include <cstdio>
#include <vector>
#include <string>

using namespace std;

inline bool r(char a) {
   if (a >= '0' && a <= '9') return true;
   else return false;
}

inline bool x(string a, string b) {
    if (a.size() > b.size()) return true;
    else if (a.size() == b.size() && a > b) return true;
    else return false;
}

int main(void){
    int w, h;
    while (cin>>w>>h && w) {
        vector<string> g(h);
        for (int i = 0; i < h; i++) cin >> g[i];
        
        vector<vector<string> > dp(h, vector<string>(w));
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                if (r(g[i][j])) dp[i][j] = g[i][j];
            }
        }
        
        string ans = "";
        for (int i = h-1; i >= 0; i--) {
            for (int j = w-1; j >= 0; j--) {
                if (!r(g[i][j])) continue;
                if (j-1 >= 0 && r(g[i][j-1])) {
                    string t = g[i][j-1] + dp[i][j];
                    if (x(t, dp[i][j-1])) dp[i][j-1] = t;
                }
                if (i-1 >= 0 && r(g[i-1][j])) {
                    string t = g[i-1][j] + dp[i][j];
                    if (x(t, dp[i-1][j])) dp[i-1][j] = t;
                }
                if (dp[i][j][0] != '0' && x(dp[i][j], ans)) ans = dp[i][j];
            }
        }
        cout << ans << endl;
    }
}