def isalpha(c)
  c.to_i.to_s != c
end

def search(x, y, w, h, mat, values)
  q = []
  q << [x, y]
  until q.empty?
    px, py = q.shift
    [[0, 1], [1, 0]].each do |mx, my|
      x = px + mx; y = py + my
      if x < w && y < h && mat[y][x]
        if (old = values[y][x]) < (now = (values[py][px].to_s + mat[y][x]).to_i)
          values[y][x] = now
          q << [x, y] if old == 0
        end
      end
    end
  end
  values
end

def solve(w, h, mat)
  values = h.times.map{ [0] * w }
  h.times do |y|
    w.times do |x|
      if mat[y][x] && values[y][x] == 0
        values[y][x] = mat[y][x].to_i
        values = search(x, y, w, h, mat, values)
      end
    end
  end
  values.flatten.max
end


while l = gets
  w, h = l.split.map(&:to_i)
  break if w == 0 && h == 0
  mat = h.times.map { gets.chomp }
  mat.map!{ |m| m.split('').map{ |c| isalpha(c) ? false : c } }
  puts solve(w, h, mat)
end