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

using namespace std;

int w, h;
vector<string> c;
string dp[100][100];

string cmax(string& a, string& b){
	if(a.size() < b.size()) return b;
	else if(a.size() == b.size()) return max(a, b);
	else return a;
}

int main(){
	while(1){
		cin >> w >> h;
		if(!w && !h) break;
		c.resize(h);
		fill(dp[0], dp[100], "");
		for(int i=0; i<h; i++){
			cin >> c[i];
		}

		string ans = "";
		for(int i=0; i<h; i++){
			for(int j=0; j<w; j++){
				if(isdigit(c[i][j])) dp[i][j] += c[i][j];
				else dp[i][j] = "";
				if(dp[i][j] == "0") dp[i][j] = "";
				ans = cmax(ans, dp[i][j]);
				dp[i+1][j] = cmax(dp[i+1][j], dp[i][j]);
				dp[i][j+1] = cmax(dp[i][j+1], dp[i][j]);
				//dp[i+1][j+1] = cmax(dp[i+1][j+1], dp[i][j]);
			}
		}
		cout << ans << endl;
	}
}
