local s = io.read()
local all9 = true
for i = 2, #s do
  if s:sub(i, i) ~= "9" then
    all9 = false
  end
end
local n = tonumber(s:sub(1, 1))
n = n + 9 * (#s - 1)
if not all9 then n = n - 1 end
print(n)
