#include <bits/stdc++.h>
using namespace std;
const long long INF = 4e18;
const int inf = 1e9;
const int N = 5e5 + 5;
const long long mod = 998244353;
void solve() {
  long long n, m;
  cin >> n >> m;
  long long f[n + 1];
  f[0] = 1;
  for (long long i = 1; i <= n; i++) {
    f[i] = (f[i - 1] * i) % m;
  }
  long long ans = 0;
  for (long long i = 1; i <= n; i++) {
    ans += ((((((n - i + 1) * (n - i + 1)) % m) * f[i]) % m) * f[n - i]) % m;
    ans %= m;
  }
  cout << ans << '\n';
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
