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