#include <bits/stdc++.h>
using namespace std;
long long int gcdExtended(long long int a, long long int b, long long int *x,
                          long long int *y);
long long int modInverse(long long int b, long long int m) {
  long long int x, y;
  long long int g = gcdExtended(b, m, &x, &y);
  if (g != 1) return -1;
  return (x % m + m) % m;
}
long long int modDivide(long long int a, long long int b, long long int m) {
  a = a % m;
  long long int inv = modInverse(b, m);
  if (inv == -1)
    cout << "Division not defined";
  else
    return (inv * a) % m;
}
long long int gcdExtended(long long int a, long long int b, long long int *x,
                          long long int *y) {
  if (a == 0) {
    *x = 0, *y = 1;
    return b;
  }
  long long int x1, y1;
  long long int gcd = gcdExtended(b % a, a, &x1, &y1);
  *x = y1 - (b / a) * x1;
  *y = x1;
  return gcd;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int t, n, m;
  cin >> n >> m;
  vector<long long int> v;
  v.push_back(0);
  long long int x = 1;
  for (long long int i = 1; i < n + 1; i++) {
    x *= i;
    x %= m;
    v.push_back(x);
  }
  long long int y = n;
  long long int ans = 0;
  long long int p = n;
  for (long long int i = 1; i < n + 1; i++) {
    long long int z = v[y] * v[i];
    z %= m;
    z *= p;
    z %= m;
    ans += z;
    ans %= m;
    y--;
    p--;
  }
  ans %= m;
  cout << ans << endl;
}
