#include <bits/stdc++.h>
using namespace std;
int fact[250001];
int main() {
  cin.sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  fact[0] = fact[1] = 1;
  for (int i = 2; i <= n; ++i) {
    fact[i] = i * 1LL * fact[i - 1] % m;
  }
  int ans = 0;
  for (int i = 1; i <= n; ++i) {
    int add = i * 1LL * fact[i] % m;
    add = add * 1LL * fact[n - i + 1] % m;
    ans = (ans + add) % m;
  }
  cout << ans;
}
