using System; using System.Collections.Generic; using System.Linq; using System.Text; class Program { static void Main(string[] args) { string line = System.Console.ReadLine().Trim(); int M = int.Parse(line); long r_x = 1; for (int i = 0; i < 2017; i++) { r_x = (r_x * 2017*2017) % M; } r_x = (2017 + r_x) % M; System.Console.WriteLine(r_x); } }