def count_palindromes(M):
    def generate_palindrome(prefix, is_even):
        s = str(prefix)
        if is_even:
            other = s[::-1]
        else:
            other = s[:-1][::-1]
        combined = s + other
        return int(combined)
    
    s = str(M)
    n = len(s)
    total = 0

    for d in range(1, n + 1):
        if d == 1:
            add = min(9, M)
            if add >= 1:
                total += add
            continue

        is_even = (d % 2 == 0)
        half = d // 2

        prefix_len = half if is_even else half + 1
        min_prefix = 10 ** (prefix_len - 1)
        max_prefix = 10 ** prefix_len - 1

        if min_prefix > max_prefix:
            continue

        max_pali = generate_palindrome(max_prefix, is_even)
        if max_pali <= M:
            count = max_prefix - min_prefix + 1
            total += count
        else:
            low = min_prefix
            high = max_prefix
            best = min_prefix - 1
            while low <= high:
                mid = (low + high) // 2
                pali = generate_palindrome(mid, is_even)
                if pali <= M:
                    best = mid
                    low = mid + 1
                else:
                    high = mid - 1
            if best >= min_prefix:
                count = best - min_prefix + 1
                total += count

    return total

N = int(input())
mod = 10**9 + 1
M = N // mod

if M == 0:
    print(0)
else:
    print(count_palindromes(M))