#include <bits/stdc++.h>
using namespace std;
long long fact[251000];
int main() {
  cin.sync_with_stdio(false);
  cout.sync_with_stdio(false);
  long long n, m;
  cin >> n >> m;
  long long ans = 0;
  fact[0] = 1;
  for (long long i = 1; i <= n; ++i) {
    fact[i] = fact[i - 1] * i;
    fact[i] %= m;
  }
  for (long long i = 0; i < n; ++i) {
    long long cnt = 1LL * (n - i) * (n - i);
    cnt %= m;
    cnt *= fact[i + 1];
    cnt %= m;
    cnt *= fact[n - i - 1];
    cnt %= m;
    ans += cnt;
    ans %= m;
  }
  cout << ans;
}
