#include using namespace std; typedef long long ll; int main() { cin.tie(0); ios::sync_with_stdio(false); ll M; cin >> M; ll x = 1; for(int i = 0; i < 2017; i++) { x *= 2017 * 2017; x %= M; } cout << (2017 + x) % M << endl; }