#!/usr/bin/env python3 # from typing import * import sys import io import math import collections import decimal import itertools import bisect import heapq def input(): return sys.stdin.readline()[:-1] # sys.setrecursionlimit(1000000) # _INPUT = """4000000000 # """ # sys.stdin = io.StringIO(_INPUT) INF = 10**10 MOD = 1000000007 def solve(N): if N < 10**9+1: return 0 N1 = N // (10**9) N2 = N % (10**9) d = len(str(N1)) ans = 0 for d1 in range(1, d): i = (d1+1)//2 - 1 ans += 9 * (10 ** i) a = N1 // (10**(d//2)) ans += int(str(int(str(a)[0])-1) + str(a)[1:]) if d % 2 == 0: b = int(str(a) + str(a)[::-1]) else: b = int(str(a) + str(a)[:-1][::-1]) if b < N1 or (b == N1 and b <= N2): ans += 1 return ans N = int(input()) print(solve(N))