#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int O = 50;
const int mod = 998244353;
const int maxn = 3e5 + 9;
const double PI = acos(-1.0);
const double E = 2.718281828459;
const double eps = 1e-8;
long long sum[maxn];
int main() {
  int n, m;
  cin >> n >> m;
  long long jc[maxn];
  jc[0] = 1;
  for (int i = 1; i <= n; i++) jc[i] = (jc[i - 1] * i) % m;
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    ans = (ans +
           1ll * (n - i) * (n - i) % m * jc[i + 1] % m * jc[n - i - 1] % m) %
          m;
  }
  cout << ans << endl;
  return 0;
}
