#include <bits/stdc++.h>
long long n, m, sol;
long long square[250005], fact[250005];
int main() {
  std::cin >> n >> m;
  fact[0] = 1LL;
  for (int i = 1; i <= n; ++i) {
    fact[i] = (i * fact[i - 1]) % m;
    square[i] = (i * (n - i + 1)) % m;
  }
  for (int i = 1; i <= n; ++i) {
    sol = (sol + (((square[n - i + 1] * fact[n - i]) % m) * fact[i]) % m) % m;
  }
  std::cout << sol;
  return 0;
}
