#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  long long n, m;
  cin >> n >> m;
  long long fact[n + 1];
  fact[0] = 1;
  fact[1] = 1;
  for (long long i = 2; i <= n; i++) {
    fact[i] = (fact[i - 1] * i) % m;
  }
  long long ans = 0;
  for (long long i = 1; i <= n; i++) {
    long long g = i - 1;
    long long t = n - g;
    long long f = (((t * t) % m * fact[i]) % m * fact[n - i]) % m;
    ans = (ans + f) % m;
  }
  cout << ans << endl;
}
