#include <bits/stdc++.h>
using namespace std;
const int maxx = 1000001;
const int inf = 1000000002;
long long fac[maxx], res[maxx];
long long n, mod;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  ;
  cin >> n >> mod;
  fac[0] = 1;
  for (int i = 1; i <= n; i++) fac[i] = fac[i - 1] * i % mod;
  for (int i = 1; i <= n; i++) {
    if (i == 1) {
      res[i] = fac[n];
      continue;
    }
    res[i] = fac[i];
    res[i] = res[i] * fac[n - i] % mod;
    res[i] = res[i] * (n - i + 1) % mod;
  }
  for (int i = 2; i <= n; i++) res[i] = (res[i] + res[i - 1]) % mod;
  long long ans = 0;
  for (int i = 1; i <= n; i++) ans = (ans + res[n - i + 1]) % mod;
  cout << ans << endl;
}
