#!/usr/bin/python2 # -*- coding: utf-8 -*- # † N = 2017 m = int(raw_input()) y = pow(N * N, N, m) y += N y %= m print y