### subroutines

def search_seq(x, y)
  q = [[x, y, $grids[y][x]]]
  max_seq = 0

  while ! q.empty?
    x0, y0, seq = q.shift
    max_seq = seq if max_seq < seq

    if x0 < $w - 1
      d = $grids[y0][x0 + 1]
      if d >= 0
        q << [x0 + 1, y0, seq * 10 + d]
      end
    end
    if y0 < $h - 1
      d = $grids[y0 + 1][x0]
      if d >= 0
        q << [x0, y0 + 1, seq * 10 + d]
      end
    end
  end

  max_seq
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].to_i
      else
        $grids[y][x] = -1
      end
    end
  end
  #p $grids

  max_seq = 0

  for y in (0...$h)
    for x in (0...$w)
      if $grids[y][x] > 0
        seq = search_seq(x, y)
        max_seq = seq if max_seq < seq
      end
    end
  end

  puts max_seq
end