#include <bits/stdc++.h>
using namespace std;
using Int = long long;
constexpr static int mod = 1e9 + 7;
constexpr static int inf = (1 << 30) - 1;
constexpr static Int infll = (1LL << 61) - 1;
int Competitive_Programming =
    (ios_base::sync_with_stdio(false), cin.tie(nullptr),
     cout << fixed << setprecision(15), 0);
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
constexpr int mod1 = 1e9 + 7;
constexpr int mod2 = 998244353;
struct Combination {
  using Int = long long;
  int mod;
  vector<Int> mfact, rfact;
  Combination(int sz, int mod) : mfact(sz + 1), rfact(sz + 1), mod(mod) {
    mfact[0] = 1LL;
    for (int i = 1; i < sz + 1; i++) {
      mfact[i] = mfact[i - 1] * i % mod;
    }
    rfact[sz] = inv(mfact[sz]);
    for (int i = sz - 1; i >= 0; i--) {
      rfact[i] = rfact[i + 1] * (i + 1) % mod;
    }
  }
  Int fact(int k) const { return mfact[k]; }
  Int pow(Int x, Int n) const {
    Int ret = 1LL;
    while (n > 0) {
      if (n & 1) (ret *= x) %= mod;
      (x *= x) %= mod, n >>= 1;
    }
    return ret;
  }
  Int inv(Int x) const { return pow(x, mod - 2); }
  Int Perm(int n, int r) const {
    if (r < 0 || n < r) return 0LL;
    return mfact[n] * rfact[n - r] % mod;
  }
  Int Binom(int p, int q) const {
    if (q < 0 || p < q) return 0LL;
    return mfact[p] * rfact[q] % mod * rfact[p - q] % mod;
  }
};
int main() {
  Int N, M;
  cin >> N >> M;
  Combination comb(N, M);
  Int ans = 0;
  for (int i = 1; i <= N; i++) {
    ans += (N + 1 - i) * comb.Perm(N - i + 1, N - i + 1) % M * comb.Perm(i, i);
    ans %= M;
  }
  cout << ans << "\n";
}
