






"""simple docstring"""



from __future__ import annotations

from collections import namedtuple
from dataclasses import dataclass





@dataclass
class 					_UpperCAmelCase       :
					SCREAMING_SNAKE_CASE_		:				int
					SCREAMING_SNAKE_CASE_		:				TreeNode | None							    =   None
					SCREAMING_SNAKE_CASE_		:				TreeNode | None							    =   None
__A		:       List[str]  				=		namedtuple('''CoinsDistribResult''', '''moves excess''')



def 						lowercase    (				__snake_case				: TreeNode | None	):

		if root is None:
				return 0

		# Validation
		def count_nodes(__snake_case				: TreeNode | None	) -> int:
				if node is None:
						return 0

				return count_nodes(node.left	) + count_nodes(node.right	) + 1

		def count_coins(__snake_case				: TreeNode | None	) -> int:
				if node is None:
						return 0

				return count_coins(node.left	) + count_coins(node.right	) + node.data

		if count_nodes(__snake_case	) != count_coins(__snake_case	):
				raise ValueError('''The nodes number should be same as the number of coins'''	)

		# Main calculation
		def get_distrib(__snake_case				: TreeNode | None	) -> CoinsDistribResult:

				if node is None:
						return CoinsDistribResult(0		,					1	)

				lowercase_       ,					lowercase_ : List[Any]							       =   get_distrib(node.left	)
				lowercase_       ,					lowercase_ : Optional[Any]							       =   get_distrib(node.right	)

				lowercase_ : Any							       =   1 - left_distrib_excess
				lowercase_ : List[Any]							       =   1 - right_distrib_excess

				lowercase_ : Optional[int]							       =   (
				    left_distrib_moves
				    + right_distrib_moves
				    + abs(__snake_case	)
				    + abs(__snake_case	)
				)
				lowercase_ : Any							       =   node.data - coins_to_left - coins_to_right

				return CoinsDistribResult(__snake_case		,					__snake_case	)

		return get_distrib(__snake_case	)[0]


if __name__ == "__main__":
						import doctest

						doctest.testmod()











"""simple docstring"""



def 						lowercase    (				__snake_case				: int = 1_0_0_0	):
		lowercase_       ,					lowercase_ : str							       =   1, 1
		lowercase_ : List[str]							       =   2
		while True:
				lowercase_ : Tuple							       =   0
				lowercase_ : List[Any]							       =   fa + fa
				lowercase_       ,					lowercase_ : Optional[int]							       =   fa, f
				index += 1
				for _ in str(__snake_case	):
						i += 1
				if i == n:
						break
		return index


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



