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