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

int h, w;
char field[100][100];
string used[100][100];

string ans;

int vx[2] = {0, 1}, vy[2] = {1, 0};

bool comp(string s1, string s2){
	if(s1 == s2)return false;
	if(s1.size() < s2.size())return true;
	else if(s1.size() > s2.size())return false;
	else{
		//今のと比較
		for(int i = 0; i < s1.size(); i++){
			if(s2[i] > s1[i]){
				return true;
			}else if(s2[i] < s1[i]){
				return false;	
			}
		}
	}
}

int main(){
	while(1){
		cin >> w >> h;
		if(h + w == 0)break;
		
		for(int i = 0; i < h; i++)for(int j = 0; j < w; j++)used[i][j] = "";


		for(int i = 0; i < h; i++)for(int j = 0; j < w; j++)
			cin >> field[i][j];

		for(int i = 0; i < h; i++){
			for(int j = 0; j < w; j++){
				if(field[i][j] >= '0' && field[i][j] <= '9'){
					if(used[i][j] == ""){
						if(field[i][j] == '0')continue;
						used[i][j] += field[i][j];
						if(comp(ans, used[i][j]))ans = used[i][j];

					}
					for(int k = 0; k < 2; k++){
						int nx = i + vx[k], ny = j + vy[k];

						if(nx < 0 || ny < 0 || nx >= h || ny >= w)continue;
						if(field[nx][ny] >= '0' && field[nx][ny] <= '9'){
						if(comp(used[nx][ny], used[i][j] + field[nx][ny])){
							used[nx][ny] = used[i][j] + field[nx][ny];
							if(comp(ans, used[nx][ny]))ans = used[nx][ny];
						}
					}
					}
				}
			}
		}

		cout << ans << endl;

		ans = "";
		

	}
	return 0;
}
