#include <bits/stdc++.h>
using namespace std;
mt19937 rnd(time(0));
bool isPrime(long long a) {
  long long i;
  for (i = 2; i * i <= a; i++) {
    if (a % i == 0) {
      return 0;
    }
  }
  return (a != 1);
}
bool isPalindrom(const string &s, int l, int r) {
  for (int i = 0; i < (r - l + 1) / 2; i++) {
    if (s[l + i] != s[r - i]) {
      return 0;
    }
  }
  return 1;
}
template <class type1>
type1 gcd(type1 a, type1 b) {
  type1 t;
  while (b) {
    t = b;
    b = a % b;
    a = t;
  }
  return a;
}
long long positiveMod(long long v, long long md) {
  v = v % md;
  if (v < 0) {
    v += md;
  }
  return v;
}
long long f[500005];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long n, p, i, j, a, b, c, res = 0;
  cin >> n >> p;
  f[0] = 1;
  for (i = 1; i < 500005; i++) {
    f[i] = f[i - 1] * i % p;
  }
  for (i = 1; i <= n; i++) {
    a = (n - i + 1) * (n - i + 1) % p * f[n - i] % p * f[i] % p;
    res += a;
    res %= p;
  }
  cout << res;
  return 0;
}
