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