#include <bits/stdc++.h>
using namespace std;
int n, m;
long long fac[555555];
int main() {
  cin >> n >> m;
  fac[0] = 1;
  for (int i = 1; i <= n; ++i) fac[i] = fac[i - 1] * i % m;
  long long ans = 0;
  for (int i = 1; i <= n; ++i)
    ans += fac[i] * fac[n - i] % m * (n - i + 1) % m * (n - i + 1) % m;
  ans %= m;
  ans = (ans % m + m) % m;
  cout << ans << "\n";
}
