import java.util.Scanner; class Main{ public static long p(long x,long n,long m) { long r; if(1>n) return 1; r=p(x*x%m,n/2,m); if(n%2>0) r=r*x%m; return r; } public static void main(String[] args) { Scanner sc=new Scanner(System.in); long m=sc.nextLong(); sc.close(); System.out.print((2017+p(2017,2017,m)*p(2017,2017,m)%m)%m); } }