#include #define range(i,a,b) for(int i = (a); i < (b); i++) #define rep(i,b) for(int i = 0; i < (b); i++) #define all(a) (a).begin(), (a).end() #define show(x) cerr << #x << " = " << (x) << endl; #define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl; const int INF = 2000000000; using namespace std; /* べき乗 x^n mod M */ typedef unsigned long long ull; ull power(ull x, ull n, ull M){ ull res = 1; if(n > 0){ res = power(x, n / 2, M); if(n % 2 == 0) res = (res * res) % M; else res = (((res * res) % M) * x ) % M; } return res; } //階乗 ull factorial(int n, ull M){ ull res = 1; range(i,1,n + 1){ res*= i; res%= M; } return res; } /* nCr コンビネーション (1,1)から(w,h)だと、引数は(w - 1, h - 1, M) */ ull combination(ull w, ull h, ull M){ //nCr = n! / ( (n - r)! * r! ) ull a = factorial(w + h, M); ull b = factorial(h, M) * factorial(w, M) % M; return a * power(b, M - 2, M) % M; } int main(){ ull m; cin >> m; cout << (2017 + power(2017 * 2017, 2017, m)) % m << endl; }