#include <bits/stdc++.h>
using namespace std;
int n, m;
long long jc[1000010];
void work() {
  scanf("%d%d", &n, &m);
  jc[0] = 1;
  for (int i = 1; i <= n; i++) jc[i] = jc[i - 1] * i % m;
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    ans = (ans + jc[i] * jc[n - i + 1] % m * (1LL * n - i + 1) % m) % m;
  }
  printf("%lld\n", ans);
}
int main() {
  int t = 1;
  while (t--) work();
  return 0;
}
