fun f(m: Int): Int { val t = 2017%m tailrec fun iter(n: Int, r: Int): Int = if (n>1) iter(n-1,(r*t)%m) else (t+r)%m return iter(2*2017,t) } fun main(args: Array) = println(f(readLine()!!.toInt()))