#include <bits/stdc++.h>
using namespace std;
const int MAX = 3e5 + 5;
const int INF = 0x3f3f3f3f;
long long n, mod, fac[MAX], ans = 0;
void init() {
  fac[1] = 1;
  for (long long i = 2; i <= 250000; ++i) {
    fac[i] = fac[i - 1] * i % mod;
  }
}
void solve() {
  scanf("%lld%lld", &n, &mod);
  init();
  for (long long i = 1; i <= n; ++i) {
    (ans += (n - i + 1) * fac[i] % mod * fac[n - i + 1] % mod) %= mod;
  }
  printf("%lld\n", ans);
}
int main(void) {
  solve();
  return 0;
}
