#include <bits/stdc++.h>
const int MAX_N = 3e5 + 5;
int n;
long long ans, mod, fac[MAX_N];
int main() {
  scanf("%d%lld", &n, &mod);
  for (int i = fac[0] = 1; i <= n; ++i) fac[i] = fac[i - 1] * i % mod;
  for (int i = 1; i <= n; ++i)
    ans += (long long)(n - i + 1) * (n - i + 1) % mod * fac[i] % mod *
           fac[n - i] % mod;
  printf("%lld\n", ans % mod);
  return 0;
}
