import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in); long M = scan.nextInt(); scan.close(); long x = (2017 * 2017) % M; long t = 1; for(int i = 0; i < 2017; i++) { t = (t * x) % M; } long ans = (2017 + t) % M; System.out.println(ans); } }