// Aizu 1126: The Secret Number
// 2017.9.15 bal4u@uu

#include <stdio.h>
#include <ctype.h>
#include <string.h>

char d[72][72], s[72][72][72];
int a[72][72];
char ans[72]; int len;

int main()
{
	int w, h, r, c;

	while (scanf("%d%d", &w, &h) && w) {;
		memset(a, 0, sizeof(a));
		for (r = 0; r < h; r++) scanf("%s", d[r]);
		for (r = 0; r < h; r++) for (c = 0; c < w; c++) {
			if (!isdigit(d[r][c])) continue;
			a[r][c] = 0;
			if (c > 0 && isdigit(d[r][c-1]))
				a[r][c] = a[r][c-1], memcpy(s[r][c], s[r][c-1], a[r][c]);
			if (r > 0 && isdigit(d[r-1][c])) {
				if (a[r-1][c] > a[r][c] || (a[r-1][c] == a[r][c] && memcmp(s[r-1][c], s[r][c], a[r][c]) > 0))
					a[r][c] = a[r-1][c], memcpy(s[r][c], s[r-1][c], a[r][c]);
			}
			if (a[r][c] == 0 && d[r][c] == '0') continue;
			s[r][c][a[r][c]] = d[r][c], a[r][c]++;
		}
		for (len = 0, r = 0; r < h; r++) for (c = 0; c < w; c++) {
			if (a[r][c] > len || (a[r][c] == len && memcmp(s[r][c], ans, len) > 0)) len = a[r][c], memcpy(ans, s[r][c], len);
		}
		ans[len] = 0;
		puts(ans);
    }
	return 0;
}