#include <bits/stdc++.h>
using namespace std;
const long long maxn = 3e5 + 100;
const long long mod = 1e9 + 7;
const long long inf = 1e18;
long long n, m, f[maxn], ans;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  f[0] = 1;
  cin >> n >> m;
  for (long long i = 1; i <= n; i++) {
    f[i] = (i * f[i - 1]) % m;
  }
  for (long long i = 1; i <= n; i++) {
    ans = (ans +
           (((((n - i + 1) * (n - i + 1) % m) * f[i]) % m) * f[n - i]) % m) %
          m;
  }
  cout << ans;
  return 0;
}
