#include <bits/stdc++.h>
using namespace std;
long long fac[250010];
int main() {
  ios::sync_with_stdio(false);
  long long n, m;
  cin >> n >> m;
  fac[0] = 1;
  for (int i = 1; i <= n; i++) {
    fac[i] = (fac[i - 1] * (long long)i) % m;
  }
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    long long termo = ((n - i) * fac[n - i]) % m;
    termo = (termo * fac[i + 1]) % m;
    ans += termo;
    ans = ans % m;
  }
  cout << ans << endl;
}
