import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int M = sc.nextInt(); long A = 2017; long B = powmod(A*A,A,M); long ans = (A%M+B)%M; System.out.println(ans); } static long powmod(long A, long k, long M){ if(k==0)return 1; if(k%2==0){ return powmod(A*A%M,k/2,M)%M; }else{ return A*powmod(A,k-1,M)%M; } } }