#include #include #include using namespace std; bool Comp(const string& lh, const string& rh) { if (lh.size() != rh.size()){ return lh.size() < rh.size(); } return lexicographical_compare(lh.begin(), lh.end(), rh.begin(), rh.end()); } void RemoveZero(string& s) { while (!s.empty() && s[0] == '0'){ s.erase(0, 1); } } main() { int w, h; while (cin >> w >> h && w){ string answer = "0"; string table[70]; for (int i = 0; i < h; ++i){ for (int j = 0; j < w; ++j){ char c; cin >> c; if (!isdigit(c)){ table[j] = ""; continue; } string up, left; up = table[j] + c; RemoveZero(up); if (j != 0){ left = table[j - 1] + c; RemoveZero(left); } if (Comp(up, left)){ table[j] = left; } else { table[j] = up; } if (Comp(answer, table[j])){ answer = table[j]; } } } cout << answer << endl; } }