#include <bits/stdc++.h>
const int maxN = 500003;
int fac[maxN];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  fac[0] = 1;
  for (int i = 1; i <= n; ++i) fac[i] = 1ll * fac[i - 1] * i % m;
  int ans = 0;
  for (int i = 1; i <= n; ++i)
    ans = (1ll * fac[i] * fac[n - i + 1] % m * (n - i + 1) + ans) % m;
  printf("%d\n", ans);
  return 0;
}
