#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, m;
  cin >> n >> m;
  if (n == 1)
    cout << 1;
  else if (n == 2)
    cout << 6;
  else {
    long long int first[n + 1];
    first[0] = 1;
    for (int i = 1; i < n + 1; i++) first[i] = (first[i - 1] * i) % m;
    long long int ans = 0;
    for (int i = 2; i < n; i++) {
      long long int ic = ((long long int)i * (long long int)(i - 1)) % m;
      long long int curr =
          (((((((ic * first[i - 2]) % m) * first[n - i]) % m) * (n - i + 1)) %
            m) *
           (n - i + 1)) %
          m;
      ans = (ans + curr) % m;
    }
    long long int add = (n * first[n]) % m;
    ans = (ans + add) % m;
    ans = (ans + first[n]) % m;
    cout << ans;
  }
  return 0;
}
