#include <bits/stdc++.h>
using namespace std;
const long long N = 2e6 + 7;
long long jc[N];
signed main() {
  long long n, m;
  cin >> n >> m;
  jc[0] = 1;
  if (n == 1) {
    cout << 1 << endl;
    return 0;
  }
  for (long long i = 1; i <= n; i++) jc[i] = (jc[i - 1] * i + m) % m;
  long long ans = (jc[n] * n + jc[n] + m) % m;
  for (long long i = 2; i <= n - 1; i++) {
    ans = (ans + (jc[i] * (n - i + 1)) % m * jc[n - i + 1]) % m;
  }
  cout << ans << endl;
}
