#include using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) #define all(x) (x).begin(), (x).end() using ll = long long; using pii = pair; using vi = vector; using vvi = vector>; const ll inf = 1e9; int main() { int m; cin>>m; int base=2017*2017%m; int ans=1; rep(i,2017) ans=ans*base%m; ans=(ans+2017)%m; cout<