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