from __future__ import annotations

def 							__SCREAMING_SNAKE_CASE							(				lowerCAmelCase:  int | str )   ->       bool:
				_UpperCAmelCase       :		Tuple 		=    str(lowerCAmelCase )
				return n == n[::-1]

def 							__SCREAMING_SNAKE_CASE							(				lowerCAmelCase:  int = 100_0000 )   ->       int:
				_UpperCAmelCase       :		Tuple 		=    0

				for i in range(1  ,      lowerCAmelCase ):
								if is_palindrome(lowerCAmelCase ) and is_palindrome(bin(lowerCAmelCase ).split("b" )[1] ):
												total += i
				return total


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





def 							__SCREAMING_SNAKE_CASE							(				lowerCAmelCase:  str  ,      lowerCAmelCase:  str )   ->       int:
				if len(lowerCAmelCase ) != len(lowerCAmelCase ):
								raise ValueError("String lengths must match!" )

				_UpperCAmelCase       :		List[Any] 		=    0

				for chara, chara in zip(lowerCAmelCase  ,      lowerCAmelCase ):
								if chara != chara:
												count += 1

				return count


if __name__ == "__main__":
					import doctest

					doctest.testmod()


