n=gets.chomp.to_i
s = 1
max_value = {"s1": 9, "s3": 900}
kq = 0
while n/10 > 0
  n = n /10
  s+= 1
end
if(s%2==0)
  kq = maxvalue["s"+(s-1).to_s]
else
  kq = maxvalue["s"+(s-1).to_s] + n - 10**s
puts kq
