#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<ctime>

using namespace std;
using ll = long long;

pair<int, int> t_dir[2] = {{1, 0}, {0, 1}};
bool is_in_field(int y, int x, int h, int w){
  return (y >= 0 && y < h && x >= 0 && x < w);
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int ti = clock();
  // start-----------------------------------------------
  int w, h;
  while(cin >> w >> h && w && h){
    string ans = "0";
    char s[70][70] = {{}};
    vector<vector<string>> dp(h, vector<string>(w, "0"));
    for(int i = 0; i < h; i++){
      for(int j = 0; j < w; j++){
        cin >> s[i][j];
        if(s[i][j] > '9') s[i][j] = -1;
      }
    }
    for(int i = h-1; i >= 0; i--){
      for(int j = w-1; j >= 0; j--){
        if(s[i][j] == -1) continue;
        string a{s[i][j]};
        string t;
        for(auto p: t_dir){
          if(is_in_field(i+p.first, j+p.second, h, w)){
            if(s[i+p.first][j+p.second] != -1){
              string u = dp[i+p.first][j+p.second];
              if((t < u && t.length() == u.length()) || t.length() < u.length()) t = u;
            }
          }
        }
        dp[i][j] = a + t;
      }
    }
    for(int i = 0; i < h; i++){
      for(int j = 0; j < w; j++){
        char c = s[i][j];
        if(c != -1 && c-'0' != 0){
          string t = dp[i][j];
          if((ans < t && ans.length() == t.length()) || ans.length() < t.length()) ans = t;
        }
      }
    }
    cout << ans << endl;
  }
  // end-----------------------------------------------
  // cerr << 1.0 * (clock() - ti) / CLOCKS_PER_SEC << endl;
}

