#include <bits/stdc++.h>
using namespace std;

#define int long long
const int dx[2] = {1, 0}, dy[2] = {0, 1};

string dp[71][71];
string s[71];
int W, H;

string dfs(int h, int w) {
  if ( dp[h][w].size() > 0 ) return dp[h][w];

  string ret = "";
  ret += s[h][w];
  for ( int i = 0; i < 2; i++ ) {
    int ny = h+dy[i], nx = w+dx[i];
    if ( ny < 0 || nx < 0 || ny >= H || nx >= W ) continue;
    if ( !isdigit(s[ny][nx]) ) continue;
    string tmp = s[h][w]+dfs(ny, nx);
    if ( tmp.size() > ret.size() ) ret = tmp;
    else if ( tmp.size() == ret.size() && tmp > ret ) ret = tmp;
  }

  return dp[h][w] = ret;  
}

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  while ( cin >> W >> H, W ) {
    for ( int i = 0; i < H; i++ ) {
      cin >> s[i];      
    }
    
    fill_n(*dp, 71*71, "");
    string ans = "";    
    for ( int i = 0; i < H; i++ ) {
      for ( int j = 0; j < W; j++ ) {
	if ( '1' <= s[i][j] && s[i][j] <= '9' ) {
	  string tmp = dfs(i, j);
	  if ( tmp.size() > ans.size() ) ans = tmp;
	  else if ( tmp.size() == ans.size() && tmp > ans ) ans = tmp;	  
	}
      }
    }

    cout << ans << endl;    
  }  
  
  return 0;
} 

