#include <bits/stdc++.h>
using namespace std;
long long a[250010], fac[250010];
int main() {
  long long n, mod;
  long long ans = 0;
  fac[0] = fac[1] = 1;
  cin >> n >> mod;
  for (int i = 2; i <= n; i++) fac[i] = (fac[i - 1] % mod * i % mod) % mod;
  for (int i = 1; i <= n; i++)
    ans = (ans + (n - i + 1) % mod * (n - i + 1) % mod * fac[i] % mod *
                     fac[n - i] % mod) %
          mod;
  cout << ans << endl;
  return 0;
}
