#include <bits/stdc++.h>
using namespace std;
const long long N = 5 * 1e5 + 100;
long long n, m, ans, f[N];
signed main() {
  scanf("%lld%lld", &n, &m);
  f[1] = f[0] = 1ll;
  for (long long i = 2; i <= n; i++) f[i] = (f[i - 1] * i) % m;
  for (long long len = 1; len <= n; len++) {
    long long add = (n + 1ll - len) * (n + 1ll - len) % m;
    add %= m;
    add = (add * f[len]) % m;
    add = (add * f[n - len]) % m;
    ans = (ans + add) % m;
  }
  printf("%lld\n", ans);
}
