#include <bits/stdc++.h>
using namespace std;
const long long maxn = 3e5 + 100;
long long n, m, a[maxn], fac[maxn];
void init() {
  fac[0] = fac[1] = 1;
  for (long long i = 2; i < maxn; ++i) fac[i] = fac[i - 1] * i % m;
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  init();
  long long ans = 0;
  for (long long i = 1; i <= n; ++i) {
    ans =
        (ans + (n - i + 1) * (n - i + 1) % m * fac[i] % m * fac[n - i] % m) % m;
  }
  cout << ans << endl;
}
