n = int(input()) if n <= 10**9: print(0) elif n >= 10**18 - 1: print(109998) else: a = [] for i in range(5): a_i = [] for j in range(10**i, 10**(i + 1)): a_i.append(j) if i == 0: a.append(j) else: a.append(j * 10**i + int(str(j)[:i][::-1])) if i <= 3: for j in a_i: a.append(j * 10**(i + 1) + int(str(j)[::-1])) a.sort() m = n // 10**9 k = 0 while m > a[k]: k += 1 if n < a[k] * 10**9 + a[k]: print(k) else: print(k + 1)