#include <bits/stdc++.h>
using namespace std;
long long int arr[300000], m;
void fact(long long int n) {
  arr[1] = 1;
  for (int i = 2; i <= n; i++) {
    arr[i] = (arr[i - 1] % m * i % m) % m;
  }
}
int main() {
  long long int n;
  cin >> n >> m;
  fact(n);
  long long int ans = 0;
  for (int i = 1; i <= n; i++) {
    long long int mul = (arr[i] % m * arr[n - i + 1] % m) % m;
    long long int aMul = ((n - i + 1) % m * mul % m) % m;
    ans = (ans % m + aMul % m) % m;
  }
  cout << ans << endl;
}
