require 'prime' n = gets.chomp.to_i if n == 4 puts 2 else puts Prime.instance.prime?(n) ? n - 1 : (1..n-1).inject(:*) % n end