'''simple docstring'''





def      a__ (		__UpperCamelCase = 1_0_0_0_0_0_0				):
      SCREAMING_SNAKE_CASE_          =  set(range(3     ,      snake_case__     ,      2				)				)
      primes.add(2				)
      for p in range(3     ,      snake_case__     ,      2				):
            if p not in primes:
                  continue
            primes.difference_update(set(range(p * p     ,      snake_case__     ,      snake_case__				)				)				)

      SCREAMING_SNAKE_CASE_          =  [float(snake_case__				) for n in range(limit + 1				)]

      for p in primes:
            for n in range(snake_case__     ,      limit + 1     ,      snake_case__				):
                  phi[n] *= 1 - 1 / p

      return int(sum(phi[2:]				)				)


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



from __future__ import annotations


def      a__ (		__UpperCamelCase				):
      SCREAMING_SNAKE_CASE_          =  str(__UpperCamelCase				)
      return n == n[::-1]


def      a__ (		__UpperCamelCase = 1_0_0_0_0_0_0				):
      SCREAMING_SNAKE_CASE_          =  0

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


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


