#include <bits/stdc++.h>
using namespace std;
long long fact[250001];
void fac(int n, int m) {
  long long ans = 1;
  fact[0] = 1;
  fact[1] = 1;
  for (int i = 2; i <= n; i++) {
    fact[i] = fact[i - 1] * i;
    fact[i] = fact[i] % m;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n, m;
  cin >> n >> m;
  fac(n, m);
  long long ans = (n * fact[n]) % m;
  long long val = 0;
  for (long long j = 2; j <= n; j++) {
    long long val2 = (n - j + 1) * (n - j + 1) % m;
    long long val1 = (fact[n - j] * val2) % m;
    val += (val1 * fact[j]) % m;
    val = val % m;
  }
  ans += val;
  ans = ans % m;
  cout << ans << endl;
}
