#include <bits/stdc++.h>
using namespace std;
const int N = 250001;
long long po[N];
long long n, p;
int main() {
  cin >> n >> p;
  po[0] = 1;
  for (int i = 1; i <= n; i++) {
    po[i] = 1LL * po[i - 1] * i % p;
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    int s = 1ll * po[n - i] * (n - i + 1) % p * (n - i + 1) % p * po[i] % p;
    ans = (ans + s) % p;
  }
  cout << ans << endl;
}
