#include <bits/stdc++.h>
using namespace std;
long long N, MOD;
long long factorial[250123];
long long invfact[250123];
long long bp(long long a, long long b) {
  if (b == 0) return 1;
  if (b == 1) return a % MOD;
  long long r = bp(a, b / 2);
  r = (r * r) % MOD;
  if (b % 2 == 1) {
    r = (r * a) % MOD;
  }
  return r;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long ans = 0;
  cin >> N >> MOD;
  factorial[0] = 1;
  invfact[0] = 1;
  for (long long i = 1; i <= 250000; i++) {
    factorial[i] = factorial[i - 1] * i;
    factorial[i] %= MOD;
    invfact[i] = bp(factorial[i], MOD - 2);
  }
  ans += (N * factorial[N]) % MOD;
  long long temp;
  for (long long i = 2; i <= N; i++) {
    temp = i * (i - 1LL);
    temp %= MOD;
    temp *= (N - i + 1LL);
    temp %= MOD;
    temp *= ((N - i + 1LL));
    temp %= MOD;
    temp *= factorial[N - i];
    temp %= MOD;
    temp *= factorial[i - 2];
    temp %= MOD;
    ans = (ans + temp) % MOD;
  }
  cout << ans;
  return 0;
}
