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