N = gets.to_i L = 10 ** 9 + 1 ans = (1..9).count { |x| L * x < N } 1.upto(40000) do |i| x = (i.to_s + i.to_s.reverse).to_i ans += 1 if L * x < N 0.upto(9) do |j| y = (i.to_s + j.to_s + i.to_s.reverse).to_i ans += 1 if L * y < N end end puts ans