#include <bits/stdc++.h>
using namespace std;
long long fact[(int)3e5 + 10], n, MOD;
void init() {
  fact[0] = 1;
  for (int i = 1; i <= 3e5; ++i) fact[i] = (fact[i - 1] * i) % MOD;
}
int main() {
  cin >> n >> MOD;
  init();
  long long ans = 0;
  for (int i = 1; i <= n; ++i)
    ans = (ans + (n - i + 1) * (fact[i] * fact[n - i + 1] % MOD)) % MOD;
  cout << ans;
  return 0;
}
