#include <bits/stdc++.h>
using namespace std;
inline long long gcd(long long a, long long b) {
  a = ((a) < 0 ? -(a) : (a));
  b = ((b) < 0 ? -(b) : (b));
  while (b) {
    a = a % b;
    swap(a, b);
  }
  return a;
}
const long long inf = 2147383647;
const long long mod = 1000000007;
const double pi = 2 * acos(0.0);
const double eps = 1e-9;
long long fact[1000000 + 6];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n, m, ans, tmp;
  cin >> n >> m;
  fact[0] = 1;
  for (long long i = (1); i <= (1000000); ++i) fact[i] = (fact[i - 1] * i) % m;
  ans = 0;
  for (long long i = (1); i <= (n); ++i) {
    tmp = ((n - i + 1) * (n - i + 1)) % m;
    tmp = (tmp * fact[n - i]) % m;
    tmp = (tmp * fact[i]) % m;
    ans = (ans + tmp) % m;
  }
  cout << ans << "\n";
  return 0;
}
