#include <bits/stdc++.h>
using namespace std;
const int N = 1000001;
long long fact[N];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n, m, ans = 0;
  cin >> n >> m;
  fact[0] = 1;
  for (int i = 1; i <= n; ++i) fact[i] = (fact[i - 1] * i) % m;
  for (int i = 0; i < n; ++i)
    ans = (ans +
           (((n - i) * (n - i)) % m) * ((fact[n - i - 1] * fact[i + 1]) % m)) %
          m;
  cout << ans << "\n";
}
