// coding 10min / debug 10min‚®‚ç‚¢ // total 20min (16:01 - 16:21) #include #include #include #include #include #include using namespace std; string supress(const string &s) { string::const_iterator it = find_if(s.begin(), s.end(), bind2nd(not_equal_to(), '0')); return string(it, s.end()); } bool str_len_less(const string &lhs, const string &rhs) { return (lhs.size() < rhs.size()) || ((lhs.size() == rhs.size()) && lhs < rhs); } int main(void) { int W, H; while(cin >> W >> H && (W || H)){ vector > ctable(W, vector (H)); vector > dptable(W + 1, vector(H + 1)); for(int y = 0; y < H; y++){ for(int x = 0; x < W; x++){ cin >> ctable[x][y]; } } for(int y = H - 1; y >= 0; y--){ for(int x = W - 1; x >= 0; x--){ if(!isdigit(ctable[x][y])) continue; string maxstr = max(dptable[x ][y + 1], dptable[x + 1][y ], str_len_less); dptable[x][y] = string(1, ctable[x][y]); dptable[x][y] += maxstr; } } string mstr; for(int y = 0; y < H; y++){ for(int x = 0; x < W; x++){ string s = supress(dptable[x][y]); mstr = max(mstr, s, str_len_less); } } cout << mstr << endl; } return 0; }