#include <bits/stdc++.h>
using namespace std;
const int MOD = (int)1e9 + 7;
inline void addmod(int& a, int val, int p = MOD) {
  if ((a = (a + val)) >= p) a -= p;
}
inline int mult(int a, int b, int p = MOD) { return (long long)a * b % p; }
int main(void) {
  int n, m;
  cin >> n >> m;
  vector<int> fact(n + 1, 1);
  for (int i = 1; i <= n; i++) {
    fact[i] = mult(i, fact[i - 1], m);
  }
  long ans = 0;
  for (int i = 1; i <= n; i++) {
    ans = (ans + mult(mult(fact[i], fact[n - i + 1], m), i, m)) % m;
  }
  cout << ans << endl;
}
