#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, MOD;
  cin >> n >> MOD;
  long long fact[n + 1];
  fact[0] = 1;
  for (long long i = 1; i <= n; i++) {
    fact[i] = fact[i - 1] * i;
    fact[i] = fact[i] % MOD;
  }
  for (long long i = 1; i <= n; i++) {
    fact[i] = fact[i] * i;
    fact[i] = fact[i] % MOD;
  }
  long long sm = 0;
  long long pr = 1;
  for (int i = 1; i <= n; i++) {
    pr = pr * i;
    pr = pr % MOD;
    sm += (fact[n + 1 - i] * pr);
    sm %= MOD;
  }
  cout << sm << endl;
}
