#include<stdio.h>
#define WH_MAX 70
int w, h;
char dp[WH_MAX * WH_MAX];
char f[WH_MAX * WH_MAX];


/* 
7 4
9R2A993
0E314A0
8A900DE
820R037
6 7
JH03HE
ID7722
0DA1AH
30C9G5
99971A
CA7EAI
AHLBEM
20 2
A1234567891234CBDEGH
BDEDF908034265091499
0 0

---------

23900037
771971
12345908034265091499
*/

void init(char *str, int n)
{
  int i;
  for(i = 0; i < n; i++)
    str[i] = '\0';
}

int is_zero(char *str)
{
  int i;
  for(i = 0;  str[i] == '0'; i++);
  if(str[i] == '\0')
    return 1;
  else
    return 0;
}

int shape(char *str)
{
  int i, j, zero = 0;
  if(str[0] == '\0')
    return 0;
  else if(is_zero(str))
    {
      str[0] = '0';
      str[1] = '\0';
      return 1;
    }
  else
    {
      for(i = 0; str[i] != '\0' && str[i] == '0'; i++, zero++);
      for(i = 0, j = zero; str[j] != '\0'; i++, j++)
	str[i] = str[j];
      str[i] = '\0';
      return i;
    }
}

void strcp(char *src, char *dst)
{
  int i;
  for(i = 0; src[i] != '\0'; i++)
    dst[i] = src[i];
  dst[i] = '\0';
}

char* max(char *s0, char *s1)
{

  int i, j, s0_n = shape(s0), s1_n = shape(s1);


  if(s0_n > s1_n)
    return s0;
  else if(s0_n < s1_n)
    return s1;
  else
    {
      for(i = 0; i < s0_n; i++)
	{
	  if(s0[i] > s1[i])
	    return s0;
	  else if(s0[i] < s1[i])
	    return s1;
	}
    }
  return s0;
}

int ok(int x, int y)
{
  return 0 <= x && x < w && 0 <= y && y <= h && '0' <= f[y * w + x] && f[y * w + x] <= '9';
}


char* dfs(int x, int y, char *str, int str_n)
{

  char right[WH_MAX * 2] = {'\0'}, below[WH_MAX  * 2] = {'\0'}, right_ret[WH_MAX * 2] = {'\0'}, below_ret[WH_MAX * 2] = {'\0'};
  if(ok(x, y))
    {
      strcp(str, right);
      strcp(str, below);
      right[str_n] = f[y * w + x];
      right[str_n + 1] = '\0';
      below[str_n] = f[y * w + x];
      below[str_n + 1] = '\0';
      str_n++;

      strcp(dfs(x + 1, y, right, str_n), right_ret);

      strcp(dfs(x, y + 1, below, str_n), below_ret);

      return max(right_ret, below_ret);
    }

  return str;
}

int main(void)
{
  char d;
  char secret_num[WH_MAX * 2] = {'\0'};
  char searched_num[WH_MAX * 2] = {'\0'};
  char s0[10], s1[10];
  int i, j;

  /* scanf("%s", s0), scanf("%s", s1); */
  /* printf("%s\n", max(s0, s1)); */

  
  while(scanf("%d %d", &w, &h), (w && h))
    {
      scanf("%c", &d);
      for(i = 0; i < h; i++)
  	{
  	  for(j = 0; j < w; j++)
  	    {
  	      scanf("%c", &f[i * w + j]);
  	    }
  	  scanf("%c", &d);
  	}


      for(i = 0; i < h; i++)
      	{
      	  for(j = 0; j < w; j++)
      	    {
      	      strcp(max(dfs(j, i, searched_num, 0), secret_num), secret_num);
      	      init(searched_num, WH_MAX * 2);
      	    }
      	}
      printf("%s\n", secret_num);
      init(secret_num, WH_MAX * 2);

    }

  return 0;

}