#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  uint64_t n, m;
  cin >> n >> m;
  vector<uint64_t> f(n + 1);
  f[0] = 1;
  for (size_t i = 1; i <= n; ++i) {
    f[i] = (f[i - 1] * i) % m;
  }
  uint64_t inc = 1;
  uint64_t res = 0;
  for (uint64_t first = n; first > 0; --first) {
    res += ((((f[first] * f[n - first]) % m) * (n - first + 1)) % m) * inc;
    res %= m;
    ++inc;
  }
  cout << res;
  return 0;
}
