#include using namespace std; using ll = long long; using ul = unsigned long; using ull = unsigned long long; ll modpow(ll x, ll n, ll mod) { ll res{ 1 }; while (n > 0) { if (n & 1) res = res * x % mod; x = x * x % mod; n >>= 1; } return res; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); ll m; cin >> m; ll res, x = 2017 * 2017; if (m == 1) res = 0; else res = (2017 + modpow(x, 2017, m)) % m; cout << res << "\n"; return 0; }