#include <bits/stdc++.h>
using namespace std;
long long n, m, fac[1000005];
long long res;
int32_t main() {
  cin >> n >> m;
  fac[0] = 1;
  for (long long i = 1; i <= n; i++) {
    fac[i] = (fac[i - 1] * i) % m;
  }
  for (long long i = 1; i <= n; i++) {
    res +=
        (((((fac[i] * (n - i + 1)) % m) * fac[n - i]) % m) * (n - i + 1)) % m;
    res %= m;
  }
  cout << res;
}
