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