#include <iostream>
#include <string>
using namespace std;

bool isdigit(char c){
	if(c >= '0' && c <= '9') return true;
	else return false;
}

int main(){
	int w,h;
	string field[70];
	while(1){
		cin >> w >> h;
		if(!w) break;
		string dp[71][71] = {};
		for(int i = 0;i < h;i++) cin >> field[i];
		string ma = "";
		for(int i = 1;i <= h;i++){
			for(int j = 1;j <= w;j++){
				if(isdigit(field[i - 1][j - 1])){
					string s1 = dp[i - 1][j],s2 = dp[i][j - 1];
					if(s1 == "" && s2 == "" && field[i - 1][j - 1] == '0') continue;
					if(s1.length() > s2.length() || (s1.length() == s2.length() && s1 > s2)){
						dp[i][j] = s1 + to_string(field[i - 1][j - 1] - '0');
					}else{
						dp[i][j] = s2 + to_string(field[i - 1][j - 1] - '0');
					}
					if(dp[i][j].length() > ma.length() || (dp[i][j].length() == ma.length() && dp[i][j] > ma)){
						ma = dp[i][j];
					}
				}
			}
		}
		cout << ma << endl;
		
	}
	return 0;
}