#include <bits/stdc++.h>
using namespace std;
int main(){
  while (1){
    int W, H;
    cin >> W >> H;
    if (W == 0 && H == 0){
      break;
    }
    vector<vector<char>> C(H, vector<char>(W));
    for (int i = 0; i < H; i++){
      for (int j = 0; j < W; j++){
        cin >> C[i][j];
      }
    }
    vector<vector<string>> dp(H, vector<string>(W, ""));
    if (isdigit(C[0][0])){
      if (C[0][0] != '0'){
        dp[0][0] += C[0][0];
      }
    }
    for (int i = 0; i < H; i++){
      for (int j = 0; j < W; j++){
        if (isdigit(C[i][j])){
          if (i > 0){
            string S = dp[i - 1][j] + C[i][j];
            if (S != "0"){
              if (dp[i][j].size() < S.size() || dp[i][j].size() == S.size() && dp[i][j] < S){
                dp[i][j] = S;
              }
            }
          }
          if (j > 0){
            string S = dp[i][j - 1] + C[i][j];
            if (S != "0"){
              if (dp[i][j].size() < S.size() || dp[i][j].size() == S.size() && dp[i][j] < S){
                dp[i][j] = S;
              }
            }
          }
        }
      }
    }
    string ans = "";
    for (int i = 0; i < H; i++){
      for (int j = 0; j < W; j++){
        if (ans.size() < dp[i][j].size() || ans.size() == dp[i][j].size() && ans < dp[i][j]){
          ans = dp[i][j];
        }
      }
    }
    cout << ans << endl;
  }
}
