#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
int mx(vector<int> &v, int l, int r) {
  int ans = -INF;
  for (int i = l; i <= r; ++i) {
    ans = max(ans, v[i]);
  }
  return ans;
}
int mn(vector<int> &v, int l, int r) {
  int ans = INF;
  for (int i = l; i <= r; ++i) {
    ans = min(ans, v[i]);
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n;
  long long mod;
  cin >> n >> mod;
  vector<long long> fact(n + 1, 1);
  for (long long i = 1; i <= n; ++i) {
    fact[i] = (fact[i - 1] * i) % mod;
  }
  long long ans = 0;
  for (long long l = 1; l <= n; ++l) {
    ans += (n - l + 1) * (n - l + 1) % mod * fact[l] % mod * fact[n - l] % mod;
    ans %= mod;
  }
  cout << ans << endl;
  return 0;
}
