'''simple docstring'''




_A										= {
    '0': 1,
    '1': 1,
    '2': 2,
    '3': 6,
    '4': 2_4,
    '5': 1_2_0,
    '6': 7_2_0,
    '7': 5_0_4_0,
    '8': 4_0_3_2_0,
    '9': 3_6_2_8_8_0,
}

_A										= {1_4_5: 1_4_5}

_A										= {
    1_4_5: 0,
    1_6_9: 3,
    3_6_3_0_1: 3,
    1_4_5_4: 3,
    8_7_1: 2,
    4_5_3_6_1: 2,
    8_7_2: 2,
}

def _UpperCamelCase (							SCREAMING_SNAKE_CASE_				):
     if n in CACHE_SUM_DIGIT_FACTORIALS:
          return CACHE_SUM_DIGIT_FACTORIALS[n]
     lowercase_       :							Optional[int]  					=       sum(DIGIT_FACTORIALS[let] for let in str(SCREAMING_SNAKE_CASE_				)				)
     lowercase_       :							List[str]  					=       ret
     return ret

def _UpperCamelCase (							SCREAMING_SNAKE_CASE_	,							SCREAMING_SNAKE_CASE_ = None				):
     lowercase_       :							Tuple  					=       previous or set()
     if n in CHAIN_LENGTH_CACHE:
          return CHAIN_LENGTH_CACHE[n]
     lowercase_       :							str  					=       sum_digit_factorials(SCREAMING_SNAKE_CASE_				)
     if next_number in previous:
          lowercase_       :							Dict  					=       0
          return 0
     else:
          previous.add(SCREAMING_SNAKE_CASE_				)
          lowercase_       :							Union[str, Any]  					=       1 + chain_length(SCREAMING_SNAKE_CASE_	,							SCREAMING_SNAKE_CASE_				)
          lowercase_       :							int  					=       ret
          return ret

def _UpperCamelCase (							SCREAMING_SNAKE_CASE_ = 60	,							SCREAMING_SNAKE_CASE_ = 1_000_000				):
     return sum(1 for i in range(1	,							SCREAMING_SNAKE_CASE_				) if chain_length(SCREAMING_SNAKE_CASE_				) == num_terms				)


if __name__ == "__main__":
 print(F"""{solution() = }""")





'''simple docstring'''




def _UpperCamelCase (							SCREAMING_SNAKE_CASE_ = 1_000				):
     lowercase_       :							Tuple  					=       [0, 3, 3, 5, 4, 4, 3, 5, 5, 4, 3, 6, 6, 8, 8, 7, 7, 9, 8, 8]
     # number of letters in twenty, thirty, ..., ninety (0 for numbers less than
     # 20 due to inconsistency in teens)
     lowercase_       :							List[Any]  					=       [0, 0, 6, 6, 5, 5, 5, 7, 6, 6]

     lowercase_       :							Optional[Any]  					=       0

     for i in range(1	,							n + 1				):
          if i < 1_000:
               if i >= 100:
                    # add number of letters for "n hundred"
                    count += ones_counts[i // 100] + 7

                    if i % 100 != 0:
                         # add number of letters for "and" if number is not multiple
                         # of 100
                         count += 3

               if 0 < i % 100 < 20:
                    # add number of letters for one, two, three, ..., nineteen
                    # (could be combined with below if not for inconsistency in
                    # teens)
                    count += ones_counts[i % 100]
               else:
                    # add number of letters for twenty, twenty one, ..., ninety
                    # nine
                    count += ones_counts[i % 10]
                    count += tens_counts[(i % 100 - i % 10) // 10]
          else:
               count += ones_counts[i // 1_000] + 8
     return count


if __name__ == "__main__":
 print(solution(int(input().strip())))




