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

vector<char> vtovi(vector<char>& vc) {
	vector<char> tmp;
	int i=0;
	while(i<vc.size() && vc[i]=='0') ++i;
	if(i==vc.size()) return tmp;
	tmp.insert(tmp.begin(),vc.begin()+i,vc.end());
	return tmp;
}
 
int main() {
	int w,h;
	while(cin >> w >> h,w) {
		vector<vector<char> > c(h,vector<char>(w));
		for(auto&e:c) for(auto&a:e) cin >> a;
		vector<vector<vector<char> > > tmp(h+1,vector<vector<char> >(w+1));
		vector<char> ans;
		for(int i=h-1;i>=0;--i) {
			for(int j=w-1;j>=0;--j) {
				if(isdigit(c[i][j])) {
					vector<char> maxi;
					if(tmp[i+1][j].size()==tmp[i][j+1].size())
						maxi=max(tmp[i+1][j],tmp[i][j+1]);
					else maxi=tmp[i+1][j].size()>tmp[i][j+1].size()?
							 tmp[i+1][j]:tmp[i][j+1];
					tmp[i][j].push_back(c[i][j]);
					tmp[i][j].insert(tmp[i][j].begin()+1,maxi.begin(),maxi.end());
					vector<char> t(vtovi(tmp[i][j]));
					if(ans.size()<t.size()) ans=t;
					else if(ans.size()==t.size()) ans=max(ans,t);
				}
			}
		}
		for(auto a:ans) cout << a;
		cout << endl;
	}
 
	return 0;
}

