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