#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  auto add = [&](int a, int b) {
    a += b;
    if (a >= m) a -= m;
    return a;
  };
  auto mul = [&](long long a, long long b) { return a * b % m; };
  vector<int> fat(n + 1);
  fat[0] = 1;
  for (int i = 1; i <= n; i++) {
    fat[i] = mul(fat[i - 1], i);
  }
  int ans = 0;
  for (int l = 1; l <= n; l++) {
    int ways = n - l + 1;
    int star = n - l + 1;
    ans = add(ans, mul(ways, mul(star, mul(fat[l], fat[n - l]))));
  }
  cout << ans << endl;
  return 0;
}
