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

char map[71][71];
char answer[71][71][71];
int w,h;


char *secretnum(char *a,char *b)
{
	int k;
	int len1,len2;
	
	len1 = strlen(a);
	len2 = strlen(b);
	
	if(len1 > len2){
		return a;
	}else if(len1 < len2 ){
		return b;
	}else{
		for(k=0;k<len1;k++){
			if(a[k] - b[k] > 0){
				return a;
			}else if(a[k] - b[k] < 0){
				return b;
			}
		}
	}
	return a;
}

int main(void)
{
	int i,j,c;
	int len;
	char ans[71];
	
	while(1)
	{
		scanf("%d %d ",&w,&h);
		if(w==0 && h==0)break;
		
		for(i=0;i<h;i++){
			scanf("%s ",map[i]);
		}

		for(i=0;i<h;i++){
			for(j=0;j<w;j++){
				answer[i][j][0] = '\0';
				if(map[i][j] - '0' < 10 && map[i][j] - '0' >= 0){
					if(i>0)strcpy(answer[i][j],secretnum(answer[i][j],answer[i-1][j]));
					if(j>0)strcpy(answer[i][j],secretnum(answer[i][j],answer[i][j-1]));
					len = strlen(answer[i][j]);
					answer[i][j][len] = map[i][j];
					answer[i][j][len+1] = '\0';
					if(answer[i][j][0] == '0')answer[i][j][0] = '\0';
				}
			}
		}
		
		ans[0] = '\0';
		for(i=0;i<h;i++){
			for(j=0;j<w;j++){
				strcpy(ans,secretnum(ans,answer[i][j]));
			}
		}
		
		printf("%s\n",ans);
	}
	return 0;
}