n = gets.chomp.to_i
n_length = n.to_s.length

def sum_odd_digits(odd_digits)
    sum = 0
    while odd_digits > 0 do
        sum += 9*(10**(odd_digits-1))
        odd_digits -= 2
    end
    sum
end

if n_length % 2 == 0
    puts sum_odd_digits(n_length-1)
else
    max_digits_sum = n-10**(n_length-1) +1
    puts max_digits_sum + sum_odd_digits(n_length-2)
end
