#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
typedef long long int ll;

using namespace std;

struct Info{
	Info(){
		length = 0;
	}
	char number[71];
	int length;
};

char** table;
Info info[71][72];

char biggest[71];
int biggest_length;

int W,H;

bool strCmp(char* base, char* comp){
	int length1 = 0,length2 = 0;
	for(int i=0;base[i] != '\0'; i++)length1++;
	for(int i=0;comp[i] != '\0'; i++)length2++;
	if(length1 != length2)return false;

	for(int i=0;base[i] != '\0'; i++){
		if(base[i] != comp[i])return false;
	}
	return true;
}

void strcpy(char* to,char* str){
	for(int i=0;str[i] != '\0';i++){
		to[i] = str[i];
		to[i+1] = '\0';
	}
}

int strCmp2(char* left,char* right){
	int i;

	if(strCmp(left,right))return 3;

	for(i=0;left[i] != '\0' && right[i] != '\0'; i++){
		if(left[i] != right[i]){
			if(left[i] < right[i])return 1;
			else{
				return 2;
			}
		}
	}
	if(left[i] == '\0')return 1;
	else{
		return 2;
	}
}


bool rangeCheck(int row,int col){
	if(row >= 0 && row <= H-1 && col >= 0 && col <= W-1)return true;
	else{
		return false;
	}
}

void func(){
	for(int i = 1; i <= H; i++){
		scanf("%s",table[i]);
	}

	biggest[0] = '\0';
	biggest_length = 0;

	for(int i = 1; i <= H; i++){
		for(int k = 1; k <=W; k++){
			if(table[i][k-1] >= '0' && table[i][k-1] <= '9'){

				if(info[i-1][k].length == 0 && info[i][k-1].length == 0){
					if(table[i][k-1] != '0'){
						info[i][k].length = 1;
						info[i][k].number[0] = table[i][k-1];
						info[i][k].number[1] = '\0';
					}
				}else if(info[i-1][k].length > info[i][k-1].length){
					strcpy(info[i][k].number,info[i-1][k].number);
					info[i][k].number[info[i-1][k].length] = table[i][k-1];
					info[i][k].number[info[i-1][k].length+1] = '\0';
					info[i][k].length = info[i-1][k].length+1;
				}else if(info[i-1][k].length < info[i][k-1].length){
					strcpy(info[i][k].number,info[i][k-1].number);
					info[i][k].number[info[i][k-1].length] = table[i][k-1];
					info[i][k].number[info[i][k-1].length+1] = '\0';
					info[i][k].length = info[i][k-1].length+1;
				}else{ //info[i-1][k].length == info[i][k-1].length
					switch(strCmp2(info[i-1][k].number,info[i][k-1].number)){
					case 1: //info[i-1][k].number < info[i][k-1].number
						strcpy(info[i][k].number,info[i][k-1].number);
						info[i][k].number[info[i][k-1].length] = table[i][k-1];
						info[i][k].number[info[i][k-1].length+1] = '\0';
						info[i][k].length = info[i][k-1].length+1;
						break;
					case 2:
					case 3:
						strcpy(info[i][k].number,info[i-1][k].number);
						info[i][k].number[info[i-1][k].length] = table[i][k-1];
						info[i][k].number[info[i-1][k].length+1] = '\0';
						info[i][k].length = info[i-1][k].length+1;
						break;
					}
				}

				if((info[i][k].length > biggest_length) || (info[i][k].length == biggest_length && strCmp2(info[i][k].number,biggest) == 2)){
					biggest_length = info[i][k].length;
					strcpy(biggest,info[i][k].number);
				}
			}
		}
	}


	printf("%s\n",biggest);
}

int main(){


	table = new char*[71];
	for(int i = 1; i <= 70; i++){
		table[i] = new char[72];
	}

	while(true){
		scanf("%d %d",&W,&H);
		if(W == 0 && H == 0)break;

		for(int i = 1; i <= H; i++){
			for(int k = 1; k <= W+1; k++){
				info[i][k].length = 0;
			}
		}

		func();
	}

	return 0;
}

Measured memory_bytes: 2976