package yukicoder; import java.util.Scanner; public class Q485 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); long M = sc.nextLong(); long ans = 1; for (int i = 0; i < 2017; ++i) { ans = ans * 2017 * 2017 % M; } ans += 2017; ans %= M; System.out.println(ans); } }