# The Secret Number from Aizu Online Judge

# 漸化式:
#    S(i, j) = max( S(i-1,j), S(i,j-1) ) D_ij if D_ij ∈ { 0,1,2,3,4,5,6,7,8,9 }
#            = φ otherwise

def secret_number(w, h, matrix)
  subsol = Array.new(h+1) { |i| Array.new(w+1) { |j| i*j==0 ? '' : nil } }
  1.upto h do |i|
    1.upto w do |j|
      c = matrix[i-1][j-1]
      subsol[i][j] = if c =~ /\d/
                       [subsol[i-1][j], subsol[i][j-1]].max_by(&:to_i) + c
                     else
                       ''
                     end
    end
  end
  subsol.map { |row| row.max_by(&:to_i) }.max_by(&:to_i).to_i
end

# ----------------------------------------
loop do
  w, h = gets.split.map(&:to_i)
  break if [w,h] == [0,0]

  matrix = h.times.map { gets.chomp.chars }
  ans = secret_number(w, h, matrix)
  puts ans
end