# -*- coding: utf-8 -*- import sys s = input() if int(s) < 10 ** 9 + 1: print(0) sys.exit() index = len(s)-9 total = 0 kaibunsu_dict = { 0: 0, 1: 9, 2: 18, 3: 108, 4: 198, 5: 1098, 6: 1998, 7: 10998, 8: 19998, 9: 109998 } total += kaibunsu_dict[index-1] def gen_palindromic(k, B, l=0): if l == k: yield 0 elif l == k - 1: for d in range(B): yield d else: begin = 1 if l == 0 else 0 m = B ** (k - l - 1) + 1 for d in range(begin, B): for n in gen_palindromic(k, B, l + 2): yield n * B + d * m left_numbers = s[:index] for x in gen_palindromic(index, 10): if x <= int(left_numbers): total += 1 len(left_numbers) print(total)