#include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define REP(i,n) for(int i=0; i=b; --i) #define ALL(c) (c).begin(), (c).end() typedef long long ll; typedef vector VI; typedef vector VL; typedef vector VVI; typedef pair P; typedef pair PL; int main() { int n = 2017, m; cin >> m; int ans = 1; REP(i,2*n) ans = (ans * n) % m; ans = (ans + n) % m; cout << ans << endl; return 0; }