#include <bits/stdc++.h>
using namespace std;
unsigned long long int x = 0;
int main() {
  unsigned long long int n, m;
  cin >> n >> m;
  vector<unsigned long long> s(n + 2);
  s[0] = 1;
  s[1] = 1;
  for (unsigned long long int j = 2; j < n + 1; j++) {
    s[j] = (s[j - 1] * (j)) % m;
  }
  for (unsigned long long int j = 0; j < n; j++) {
    x = x + ((((((n - j) * s[j + 1]) % m) * (n - j)) % m) * s[n - j - 1]) % m;
    x = x % m;
  }
  cout << x % m << endl;
}
