#include <bits/stdc++.h>
using namespace std;
const int MAX = 250010;
int main() {
  ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  int n, m;
  cin >> n >> m;
  vector<long long> fact(MAX);
  fact[0] = 1;
  for (int i = 1; i < MAX; ++i) {
    fact[i] = fact[i - 1] * i % m;
  }
  long long ans = 0;
  ans += fact[n] * n % m;
  for (int i = 1; i < n; ++i) {
    long long p = n - i;
    ans += (p * p % m * fact[i + 1] % m) * fact[n - i - 1] % m;
    ans %= m;
  }
  cout << ans << "\n";
  return 0;
}
