n = int(input().strip()) ls = [ 1000000001, 11000000011, 111000000111, 1111000001111, 11111000011111, 111111000111111, 1111111001111111, 11111111011111111, 111111111111111111, ] total = 0 x_ = 0 for k in range(9, 0, -1): for a in ls: x = x_ + a for _ in range(k): if n > x: total += 1 x += a else: print(total) raise SystemExit x_ += 111111111111111111 print(total)