#include <bits/stdc++.h>
const int mod = 998244353;
using namespace std;
long long a[300000];
int main() {
  int n, m;
  cin >> n >> m;
  a[0] = 1;
  for (int i = 1; i <= n; ++i) {
    a[i] = (a[i - 1] * i) % m;
  }
  long long ans = 0;
  for (int i = 1; i <= n; ++i) {
    long long tmp = a[i];
    tmp = (tmp * (n - i + 1)) % m;
    tmp = (tmp * a[n - i + 1]) % m;
    ans = (ans + tmp) % m;
  }
  cout << ans << endl;
}
