#include <bits/stdc++.h>
using namespace std;
long long M = 1000000007;
long long fac[2000000];
signed main() {
  ios_base::sync_with_stdio(false);
  long long n, m, ans = 0;
  cin >> n >> m;
  fac[0] = 1;
  for (long long i = 1; i <= n; i++) fac[i] = ((i % m) * (fac[i - 1] % m)) % m;
  for (long long i = 1; i <= n; i++) {
    long long z = ((n - i + 1) % m * fac[i] % m) % m;
    ans = (ans % m + ((fac[n - i + 1] % m) * z % m) % m) % m;
  }
  cout << ans % m;
}
