#include <bits/stdc++.h>
using namespace std;
const int N = 2.5e5 + 3;
long long n, m, ans, fac[N];
long long qpow(long long a, long long b) {
  long long ret = 1;
  while (b) {
    if (b & 1) ret = ret * a % m;
    a = a * a % m;
    b >>= 1;
  }
  return ret;
}
int main() {
  cin >> n >> m;
  fac[0] = 1;
  for (int i = 1; i <= n; i++) fac[i] = fac[i - 1] * i % m;
  for (int i = 1; i < n; i++) {
    ans = (ans + (long long)(n - i + 1) * (n - i + 1) % m * fac[n - i] % m *
                     fac[i] % m) %
          m;
  }
  ans = (ans + fac[n]) % m;
  printf("%lld\n", ans);
  return 0;
}
