import std.stdio;
import std.bigint;
import std.conv;
import std.string;

string[] c;
bool isNumber[][];
BigInt dp[][];

void main()
{
  int w,h;
  string[] input;
  while(true){
    input=readln.split;
    w=input[0].to!int;
    h=input[1].to!int;
    if((w|h)==0)break;
    c=new string[h];
    isNumber=new bool[][h];
    dp=new BigInt[][h];
    for(int i=0;i<h;i++){
      c[i]=readln;
      isNumber[i]=new bool[w];
      dp[i]=new BigInt[w];
      for(int j=0;j<w;j++)
	isNumber[i][j]=('0'<=c[i][j]&&c[i][j]<='9');
    }
    dp[0][0]=isNumber[0][0]?c[0][0]-'0':0;
    BigInt max=dp[0][0];
    for(int i=1;i<h;i++){
      if(!isNumber[i][0]){
	dp[i][0]=0;
	continue;
      }
      dp[i][0]=dp[i-1][0]*10+(c[i][0]-'0');
      max=dp[i][0]>max?dp[i][0]:max;
    }
    for(int j=1;j<w;j++){
      if(!isNumber[0][j]){
	dp[0][j]=0;
	continue;
      }
      dp[0][j]=dp[0][j-1]*10+(c[0][j]-'0');
      max=dp[0][j]>max?dp[0][j]:max;
    }
    for(int i=1;i<h;i++){
      for(int j=1;j<w;j++){
	if(!isNumber[i][j]){
	  dp[i][j]=0;
	  continue;
	}
	BigInt localmax=dp[i-1][j]>dp[i][j-1]?dp[i-1][j]:dp[i][j-1];
	dp[i][j]=localmax*10+(c[i][j]-'0');
	max=dp[i][j]>max?dp[i][j]:max;
      }
    }

    writeln(max);
  }
}