
primes :: [Int]
primes = 2 : filter isPrime [3, 5 ..]
  where isPrime x = null $ filter ((== 0) . (`mod` x)) $ takeWhile ((<= x) . (^ 2)) primes

main = do
  n <- read <$> getLine :: IO Int
  let p = primes !! n
  print $ foldr1 (\a b -> (a + b) `mod` p) $ take (p-1) $ iterate ((`mod` p) . (* 10)) 1