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