#include <bits/stdc++.h>
using namespace std;
const long long large = 1e6 + 10;
const long long MOD = 998244353;
const long long mod = 1e9 + 7;
const long long inf = 1e18;
const long long N = 2e2 + 99;
void solve() {
  long long n, mod;
  cin >> n >> mod;
  long long fac[n + 10];
  fac[0] = 1;
  for (long long i = 1; i <= n; i++) fac[i] = fac[i - 1] * i % mod;
  long long ans = 0;
  for (long long len = 1; len <= n; len++) {
    ans += (n - len + 1) * (fac[len] * fac[n - len + 1] % mod);
    ans %= mod;
  }
  cout << ans << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie();
  cout.tie();
  ;
  int kse = 1;
  long long cnt = 1;
  while (kse--) {
    solve();
    cnt++;
  }
}
