
import itertools
import math



def        UpperCamelCase    (							lowerCAmelCase__		):
					'''simple docstring'''





					if 1 < number < 4:
										# 2 and 3 are primes
										return True
					elif number < 2 or number % 2 == 0 or number % 3 == 0:
										# Negatives, 0, 1, all even numbers, all multiples of 3 are not primes
										return False

					# All primes number are in format of 6k +/- 1
					for i in range(5 ,			int(math.sqrt(_snake_case		) + 1		) ,			6		):
										if number % i == 0 or number % (i + 2) == 0:
															return False
					return True



def        UpperCamelCase    (							):
					'''simple docstring'''
					lowercase							=						2
					while True:
										if is_prime(_snake_case		):
															yield num
										num += 1



def        UpperCamelCase    (							lowerCAmelCase__ = 1_0001		):
					'''simple docstring'''
					return next(itertools.islice(prime_generator() ,			nth - 1 ,			_snake_case		)		)


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








"""simple docstring"""
from __future__ import annotations






def 		lowercase							(     _snake_case						:      int | str     )     ->bool:
	"""simple docstring"""





	__snake_case	:						List[str]						=				str(_snake_case     )
	return n == n[::-1]






def 		lowercase							(     _snake_case						:      int = 1_000_000     )     ->str:
	"""simple docstring"""





	__snake_case	:						Union[str, Any]						=				0

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


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





