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

#define int long long
#define pb push_back 
#define pf push_front 
#define mp make_pair
#define fr first
#define sc second
#define Rep(i, n) for ( int i = 0 ; i < (n); i++ )
#define All(v) v.begin(), v.end()

typedef pair<int, int> Pii; typedef pair<int, Pii> Pip;
const int INF = 1107110711071107;

int h, w;
char c[71][71];

signed main() {
  while ( cin >> w >> h, w | h ) {
    vector<string> dp[71];
    Rep(i, h) dp[i] = vector<string>(71);
    Rep(i, h) Rep(j, w) {
      cin >> c[i][j];
      dp[i][j] = "0";
    }
  
    Rep(i, h) Rep(j, w) {  
      if ( '0' <= c[i][j] && c[i][j] <= '9' ) dp[i][j] = c[i][j];
    }
  
    for ( int i = 0; i < h; i++ ) {
      Rep(j, w) {
	if ( '0' <= c[i][j] && c[i][j] <= '9' ) {
	  if ( i && dp[i-1][j] != "0" ) {
	    if ( dp[i][j].size() <= dp[i-1][j].size() ) {
	      dp[i][j] = dp[i-1][j]+c[i][j];
	    } else if ( dp[i][j].size()-1 == dp[i-1][j].size() ) {
	      dp[i][j] = max(dp[i][j], dp[i-1][j]+c[i][j]);
	    }
	  }
	  if ( j && dp[i][j-1] != "0" ) {
	    if ( dp[i][j].size() <= dp[i][j-1].size() ) {
	      dp[i][j] = dp[i][j-1]+c[i][j];
	    } else if ( dp[i][j].size()-1 == dp[i][j-1].size() ) {
	      dp[i][j] = max(dp[i][j], dp[i][j-1]+c[i][j]);
	    }
	  }
	}
      }
    }

    string ans = "";
    Rep(i, h) Rep(j, w) {
      if ( ans.size() < dp[i][j].size() ) ans = dp[i][j];
      else if ( ans.size() == dp[i][j].size() ) ans = max(ans, dp[i][j]);
    }

    cout << ans << endl;
  }
  
}