#include<iostream>
#include<string>
using namespace std;

int H,W;
char S[71][71];
string maxs,DP[100][100];

int main()
{
  while(1){
    cin>>W>>H;
    if(W==0&&H==0)break;
    maxs.erase(maxs.begin(),maxs.end());
    for(int i=1;i<H+1;i++){
      for(int j=1;j<W+1;j++){
	cin>>S[i][j];
	DP[i][j].erase(DP[i][j].begin(),DP[i][j].end());
      }
    }
    for(int i=1;i<H+1;i++){
      for(int j=1;j<W+1;j++){
        if(S[i][j]=='0' && DP[i-1][j].empty() && DP[i][j-1].empty())continue;
	if(S[i][j]>='0' && S[i][j]<='9'){
	  if(DP[i-1][j].length()>DP[i][j-1].length())DP[i][j]=DP[i-1][j]+S[i][j];
	  else if(DP[i-1][j].length()<DP[i][j-1].length())DP[i][j]=DP[i][j-1]+S[i][j];
          else if(DP[i-1][j]>DP[i][j-1])DP[i][j]=DP[i-1][j]+S[i][j];
	  else DP[i][j]=DP[i][j-1]+S[i][j];
	  if(maxs.length()<DP[i][j].length())maxs=DP[i][j];
          else if(maxs.length()==DP[i][j].length() && maxs<DP[i][j])maxs=DP[i][j];
	}
      }
    }
    cout<<maxs<<endl;
  }
  return 0;
}