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