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