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