require 'prime'

def solve(p)
  (2...p-1).each_with_object([1, 10 % p]){ |i, arr| arr << (arr[1] * arr[-1]) % p }.reduce(:+) % p
end
n = gets.to_i
p solve(Prime.each.lazy.drop_while{ |p| p <= 2 * n }.take(1).to_a[0])