#include using namespace std; #define int long long signed main(){ int M; cin>> M; int s=1; for(int i=0; i<2017; i++){ (s*=((2017%M)*(2017%M)))%=M; } (s+=2017)%=M; cout<< s<< endl; }