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

//#define int int64_t

#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,x,...) x
#define REP1(i, s, cond, cal) for (signed i = signed(s); i cond; i cal)
#define REP2(i, s, n) REP1(i, s, < signed(n), ++)
#define REP3(i, n) REP2(i, 0, n)
#define rep(...) CHOOSE((__VA_ARGS__,REP1,REP2,REP3))(__VA_ARGS__)

#define all(c) begin(c), end(c)
#define maxup(ans, x) (ans = (ans < x ? x : ans))
#define minup(ans, x) (ans = (ans > x ? x : ans))

#define breakif(cond) if(cond) break; else

template<typename T>
inline void input(vector<T>& v) { for (auto& x : v) cin >> x; }

using VV = vector<vector<int>>;
using V = vector<int>;
using P = pair<int, int>;
using IP = pair<int, P>;

const int INF = 1 << 29;

signed main() {
	int w, h;
	while (cin >> w >> h && w) {
		VV data(h, V(w));
		rep(i, h) rep(j, w) {
			char c; cin >> c;
			if (c < '0' || c > '9') data[i][j] = -1;
			else data[i][j] = c - '0';
		}
		vector<vector<string>> dp(h, vector<string>(w));
		auto comp = [](string& a, string& b) {
			return a.size() != b.size() ? a.size() < b.size()
				: a < b;
		};
		string ans = "";
		rep(i, h) rep(j, w) {
			string a = to_string(data[i][j]);
			string b = a;
			if (a == "-1") continue;
			if (i - 1 >= 0 && dp[i - 1][j] != "-1") a = dp[i - 1][j] + to_string(data[i][j]);
			if (j - 1 >= 0 && dp[i][j - 1] != "-1") b = dp[i][j - 1] + to_string(data[i][j]);
			string x = comp(a, b) ? b : a;
			if (x != "0") {
				dp[i][j] = x;
				if (comp(ans, x)) ans = x;
			}
		}

		cout << ans << endl;
	}
}