#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 5;
int mod = 1e9 + 7;
long long qpow(long long a, long long b) {
  long long ans = 1;
  a %= mod;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1) ans = ans * a % mod;
    a = a * a % mod;
  }
  return ans;
}
long long gcd(long long a, long long b) { return b > 0 ? gcd(b, a % b) : a; }
int n, m, T;
int a[maxn];
int fac[maxn];
void init() {
  fac[0] = 1;
  for (int i = 1; i <= n; i++) {
    fac[i] = 1ll * fac[i - 1] * i % mod;
  }
}
int main() {
  cin >> n >> mod;
  init();
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    ans = (ans + 1ll * (n - i + 1) * fac[n - i + 1] % mod * fac[i] % mod) % mod;
  }
  cout << ans << endl;
  return 0;
}
