#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) {
    long long n, m;
    cin >> n >> m;
    vector<long long> fact(n + 1, 1);
    for (int i = 1; i < n + 1; i++) fact[i] = (long long)i * fact[i - 1] % m;
    long long ans = fact[n] * n % m;
    for (long long i = 1; i < n; i++) {
      long long temp1 = (n - i) * (n - i) % m;
      long long temp2 = (i + 1) * i % m;
      long long temp3 = fact[i - 1] * fact[n - i - 1] % m;
      ans = (ans + ((temp1 * temp2 % m) * temp3 % m)) % m;
    }
    cout << ans << endl;
  }
  return 0;
}
