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

def search(x, y, w, h, mat)
  values = h.times.map{ [0] * w }
  pre = h.times.map{ [-1] * w }  # 0 - left, 1 - up
  values[y][x] = mat[y][x].to_i
  pos = nil
  q = []
  q << [x, y]
  until q.empty?
    px, py = q.shift
    pos = [px, py]
    x = px + 1; y = py
    if x < w && mat[y][x]
      if (old = values[y][x]) < (now = (values[y][x - 1].to_s + mat[y][x]).to_i)
        values[y][x] = now
        pre[y][x] = 0
        q << [x, y] if old == 0
      end
    end
    x = px; y = py + 1
    if y < h && mat[y][x]
      if (old = values[y][x]) < (now = (values[y - 1][x].to_s + mat[y][x]).to_i)
        values[y][x] = now
        pre[y][x] = 1
        q << [x, y] if old == 0
      end
    end
  end
  footprint = []
  while pos[0] == x && pos[1] == y
    footprint << pos
    pos = pre[y][x] == 0 ? [x - 1, y] : [x, y - 1]
  end
  [values.flatten.max, footprint.reverse]
end

def solve(w, h, mat)
  ret = 0
  route = []
  h.times do |y|
    w.times do |x|
      if mat[y][x] && !route.include?([x, y])
        n, footprint = search(x, y, w, h, mat)
        if n > ret
          ret = n
          route = footprint
        end
      end
    end
  end
  ret
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