#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, mod;
  cin >> n >> mod;
  long long int fact[n + 1];
  fact[0] = 1;
  for (long long int i = 1; i <= n; i++) {
    fact[i] = fact[i - 1] * i % mod;
  }
  long long int ans = 0;
  for (long long int i = 1; i <= n; i++) {
    ans += ((n - i + 1) * (fact[i] * fact[n - i + 1] % mod)) % mod;
  }
  ans = ans % mod;
  cout << ans << endl;
}
