#include <bits/stdc++.h>
const int N = (int)5e5 + 7;
const int inf = (int)1e9 + 7;
const int mod = (int)1e9 + 7;
const long long linf = (long long)1e18 + 7;
const int dx[] = {-1, 0, 1, 0, 1, -1, -1, 1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
using namespace std;
int a[N];
int total(int n) {
  int cnt = 0;
  for (int i = (1); i <= (n); i++) {
    int mn = a[i], mx = a[i];
    for (int j = (i); j <= (n); j++) {
      mn = min(mn, a[j]);
      mx = max(mx, a[j]);
      cnt += (mx - mn == j - i);
    }
  }
  return cnt;
}
int slow(int n) {
  for (int i = (1); i <= (n); i++) a[i] = i;
  int ans = 0;
  do {
    ans += total(n);
  } while (next_permutation(a + 1, a + 1 + n));
  return ans;
}
int n, m;
int dp[N];
int first(int n) {
  if (n == 1) return 1;
  if (~dp[n]) return dp[n];
  return dp[n] = first(n - 1) * 1ll * n % m;
}
int calc(int n) {
  int ans = 0;
  for (int len = (1); len <= (n); len++) {
    int x = first(len) * 1ll * first(n - len + 1) % m;
    ans += (n - len + 1) * 1ll * x % m;
    ans %= m;
  }
  return ans;
}
int main() {
  cin >> n >> m;
  memset(dp, -1, sizeof(dp));
  cout << calc(n);
  exit(0);
}
