#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 7;
long long mod, n, fac[N];
int main() {
  scanf("%lld%lld", &n, &mod);
  fac[0] = 1LL;
  for (int i = 1; i <= n; i++) fac[i] = fac[i - 1] * i % mod;
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    ans = (ans + fac[i] * fac[n - i + 1] % mod * (n - i + 1) % mod + mod) % mod;
  }
  printf("%lld\n", ans);
}
