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

char max[72];
char matrix[72][72];
char num[72][72][72];

int large(char *num1, char *num2)
{
	if (strlen(num1) < strlen(num2)){
		return (-1);
	}
	if (strlen(num1) == strlen(num2)){
		return (strcmp(num1, num2));
	}

	return (1);
}

int main(void)
{
	int W, H, C;
	int i, j;
	int x, y;
	char c, c1, c2;
	
	
	while (1){
		scanf("%d%d", &W, &H);
		if (W == 0 && H == 0){
			break;
		}
		
		memset(matrix, 0, sizeof(matrix));
		for (y = 1; y <= H; y++){
			scanf("%s", &matrix[y][1]);
		}
		

		memset(num, 0, sizeof(num));
		max[0] = '\0';
		for (y = 1; y <= H; y++){
			for (x = 1; x <= W; x++){
				c = matrix[y][x];
				if ('0' <= c && c <= '9'){
					if (large(num[y - 1][x], num[y][x - 1]) > 0){
						strcpy(num[y][x], num[y - 1][x]);
					}
					else {
						strcpy(num[y][x], num[y][x - 1]);
					}
					num[y][x][strlen(num[y][x])] = c;
					num[y][x][strlen(num[y][x]) + 1] = '\0';
//printf("[%s]", num[y][x]);
					
					
					if (large(max, num[y][x]) < 0){
						strcpy(max, num[y][x]);
					}
					
				}
//				else{
//printf("[*]");
//				}
			}
//printf("\n");

		}
		for (x = 0; max[x] == '0'; x++);
		printf("%s\n", &max[x]);
	}
	
	return (0);
}