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