p = int(input()) t = p-1 ans = 0 for i in range(p-1,-1,-1): ans += t ans %= p t *= i t %= p print(ans)