#include <bits/stdc++.h>
using namespace std;
const int64_t maxn = 3e5 + 42;
int64_t F[maxn], U[maxn];
int64_t fact(int64_t n, int64_t m) {
  if (U[n]) {
    return F[n];
  } else {
    U[n] = 1;
    return F[n] = n ? n * fact(n - 1, m) % m : 1;
  }
}
int64_t bpow(int64_t x, int64_t n, int64_t m) {
  return n ? n % 2 ? x * bpow(x, n - 1, m) % m : bpow(x * x % m, n / 2, m) : 1;
}
int64_t inv(int64_t x, int64_t m) { return bpow(x, m - 2, m); }
int64_t nCr(int64_t n, int64_t r, int64_t m) {
  return fact(n, m) * inv(fact(r, m), m) % m * inv(fact(n - r, m), m) % m;
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int64_t n, m;
  cin >> n >> m;
  int64_t ans = 0;
  for (int64_t k = 1; k <= n; k++) {
    ans += (n - k + 1) * (n - k + 1) % m * inv(nCr(n, k, m), m) % m;
    ans %= m;
  }
  cout << ans * fact(n, m) % m << endl;
  return 0;
}
