#include <bits/stdc++.h>
using namespace std;
int mod = 1e9 + 7, A = 3e5 + 5;
int mul(int x, int y) { return (1LL * x * y) % mod; }
int sum(int x, int y) { return (x + y) % mod; }
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n;
  cin >> n >> mod;
  int fact[A];
  fact[0] = 1;
  for (int i = 1; i < A; i++) fact[i] = mul(fact[i - 1], i);
  int ans = 0;
  for (int i = 1; i <= n; i++)
    ans = sum(ans, mul(n - i + 1, mul(fact[n - i + 1], fact[i])));
  cout << ans;
  return 0;
}
