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