# coding: utf-8 # Here your code ! a = int(input()) b = ((2017*2017)**2017+2017)%a print(b)