### subroutines

def greater?(s0, s1)
  sl0 = s0.length
  sl1 = s1.length
  sl0 > sl1 || (sl0 == sl1 && s0 > s1)
end

### main

loop do
  $w, $h = gets.split.map(&:to_i)
  break if ($w | $h) == 0

  $grids = $h.times.map{[]}

  for y in (0...$h)
    line = gets.strip
    for x in (0...$w)
      case line[x]
      when '0'..'9'
        $grids[y][x] = line[x]
      else
        $grids[y][x] = nil
      end
    end
  end
  #p $grids

  max_seq = ''
  dp = $h.times.map{$w.times.map{''}}

  for y in (0...$h)
    for x in (0...$w)
      g = $grids[y][x]
      next if g.nil?

      seq = g

      if x > 0
        seq0 = dp[y][x - 1] + g
        seq = seq0 if greater?(seq0, seq)
      end
      if y > 0
        seq1 = dp[y - 1][x] + g
        seq = seq1 if greater?(seq1, seq)
      end

      next if seq == '0'

      dp[y][x] = seq
      max_seq = seq if greater?(seq, max_seq)
    end
  end

  puts max_seq
end