#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> f(n + 1, 0);
  f[0] = 1;
  for (int i = 1; i <= n; i++) {
    f[i] = (long long)f[i - 1] * i % m;
  }
  int ans = 0;
  for (int len = 1; len <= n; len++) {
    long long tmp = (long long)(n - len + 1) * (n - len + 1);
    tmp %= m;
    tmp = (tmp * f[n - len]) % m;
    tmp = (tmp * f[len]) % m;
    ans += tmp;
    if (ans >= m) {
      ans -= m;
    }
  }
  cout << ans << "\n";
  return 0;
}
