#include #include #include #include using namespace std; int h, w; char input[100][100]; string table[100][100]; string ans; string& comp(string& a, string& b) { if(a.size() != b.size()) { return (a.size() > b.size()) ? a : b; } if(a > b) return a; return b; } void Run(int x, int y) { char c = input[x][y]; if('0' <= c && c <= '9') { string& s = comp(table[x+1][y], table[x][y+1]); table[x][y] = c + s; string ss = table[x][y]; int i; for(i = 0; i < (int)ss.size(); ++i) if(ss[i] != '0') break; ss = ss.substr(i); ans = comp(ans, ss); } } int main() { while(cin >> w >> h && w && h) { ans = ""; for(int i = 0; i < 100; ++i) for(int j = 0; j < 100; ++j) table[i][j] = ""; for(int y = 0; y < h; ++y) for(int x = 0; x < w; ++x) cin >> input[x][y]; for(int y = h-1; y >= 0; --y) for(int x = w-1; x >= 0; --x) Run(x, y); cout << ans << endl; } }