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