#include using namespace std; typedef long long ll; typedef long double ld; #define rep(i,n) for (int i = 0; i < (n); ++i) templatebool chmax(T &a, const T &b) { if (abool chmin(T &a, const T &b) { if (b0;k>>=1){ if(k&1){ res=(res*n)%m; } n=(n*n)%m; } return res; } int main(){ cin.tie(0); ios::sync_with_stdio(false); int m;cin >> m; ll x=2017+pow_mod(2017*2017,2017,m); x%=m; cout << x << endl; }