P=int(input()) a=0 f=P-1 for i in range(P-1,-1,-1):a+=f;f=f*i%P print(a%P)