import strutils const n = 2017 * 2017 let m = parseInt stdin.readLine var v = 1 for _ in 0 ..< 2017: v = (n mod m) * (v mod m) echo (v + 2017) mod m