n=gets.chomp.to_i
t = n
stt = 1
max_value = {"s1": 9, "s3": 909}
kq = 0
while t/10 > 0
  t = t /10
  stt+= 1
end
if n%10 == 0
  stt-=1
end
if stt == 1
  kq = n - 1
elsif(stt%2==0)
  kq = max_value["s#{stt-1}".to_sym]
else
  kq = max_value["s#{stt-2}".to_sym] + n + 1 - 10**(stt-1)
  kq = n%10 == 0 ? kq - 1 : kq
end
puts kq
