#include <bits/stdc++.h>
using namespace std;
int INF = 0x3f3f3f3f;
int mod = 1e9 + 7;
int MAXN = 12345;
double eps = 1e-7;
int dcmp(double a, double b) { return (a - b < eps) ? -1 : (a - b >= eps); }
long long tmp[251234];
int main(int argc, char **argv) {
  ios::sync_with_stdio(false);
  int n, m, t, x, y, u, v;
  scanf("%d%d", &n, &m);
  long long ans = 0;
  tmp[0] = 1;
  for (int i = 1; i <= n; ++i) {
    tmp[i] = (tmp[i - 1] * i) % m;
  }
  for (int i = 1; i <= n; ++i) {
    ans = (ans +
           ((((((tmp[i] * (n - i + 1)) % m) * (n - i + 1)) % m) * tmp[n - i]) %
            m)) %
          m;
  }
  printf("%lld\n", ans);
  return 0;
}
