#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

typedef vector<string> VS;
typedef vector<VS> VVS;

void remove_leading_zeros ( string& str )
{
	while ( str[0] == '0' ) { str = str.substr( 1 ); }
}

bool str_comp( const string& a, const string& b )
{
	if ( a.size() != b.size() ) {;
		return a.size() < b.size();
	}
	return a < b;
}

int main ( void )
{
	int w, h;
	while ( cin >> w >> h, w | h ) {
		VS mat( h );
		for ( int i = 0; i < h; ++i ) {
			cin >> mat[i];
		}

		VVS d( h, VS( w, "" ) );

		string ans = "";
		if ( isdigit( mat[0][0] ) ) {
			d[0][0] = string( 1, mat[0][0] );
		}
		for ( int y = 0; y < h; ++y ) {
			for ( int x = 0; x < w; ++x ) {
				if ( !isdigit( mat[y][x] ) ) {
					continue;
				}
				if ( y ) {
					d[y][x] = max( d[y][x], d[y - 1][x] + mat[y][x], str_comp );
					remove_leading_zeros( d[y][x] );
				}
				if ( x ) {
					d[y][x] = max( d[y][x], d[y][x - 1] + mat[y][x], str_comp );
					remove_leading_zeros( d[y][x] );
				}
				//cout << x << ", " << y << " = " << d[y][x] << endl;
				ans = max( ans, d[y][x], str_comp );
			}
		}

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