import java.util.*; public class A{ static Scanner s = new Scanner(System.in); static final int _2017_2 = 2017*2017; public static void main(String[] args) { int m=s.nextInt(); long result = _2017_2; for(int i=1;i<2017;i++) { result*=_2017_2; result%=m; } result+=2017; result%=m; System.out.println(result); } }