#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 250000 + 7;
long long fact[MAX_N];
long long power(long long a, long long n, long long m) {
  long long x = 1;
  while (n) {
    if (n & 1) {
      x = x * a % m;
    }
    a = a * a % m;
    n >>= 1;
  }
  return x;
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  fact[0] = 1;
  for (int i = 1; i <= n; i++) {
    fact[i] = fact[i - 1] * i % m;
  }
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    ans += (long long)(n - i + 1) * (long long)(n - i + 1) % m * fact[i] % m *
           fact[n - i] % m;
    ans %= m;
  }
  printf("%lld\n", ans);
  return 0;
}
