N = gets.to_i L = 10 ** 9 + 1 b = 1 ans = 0 while L * b < N ans += (1..9).count { |x| L * b * x <= N } b = b * 10 + 1 end puts ans