#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 10;
long long c[N][50], pri[N], phi, fac[N], inv[N], skc, len, n;
void upd(long long &x, long long y) { x = (x + y) % skc; }
long long qpow(long long A, long long B) {
  long long C = 1;
  for (; B; B >>= 1, A = A * A % skc)
    if (B & 1) C = A * C % skc;
  return C;
}
void prep() {
  phi = skc;
  long long x = skc;
  for (long long i = 2; i * i <= x; ++i) {
    if (x % i) continue;
    pri[++len] = i;
    phi = phi / i * (i - 1);
    while (x % i == 0) x /= i;
  }
  if (x > 1) pri[++len] = x, phi = phi / x * (x - 1);
  fac[0] = inv[0] = fac[1] = inv[1] = 1;
  for (register long long i = (2); i <= (n); ++i) {
    x = i;
    for (register long long j = (1); j <= (len); ++j) {
      c[i][j] = c[i - 1][j];
      if (x % pri[j] != 0) continue;
      while (x % pri[j] == 0) c[i][j]++, x /= pri[j];
    }
    fac[i] = fac[i - 1] * x % skc;
    inv[i] = qpow(fac[i], phi - 1);
  }
}
long long C(long long A, long long B) {
  if (A < 0 || B < 0 || B - A < 0) return 0;
  long long ans = fac[B] * inv[A] % skc * inv[B - A] % skc;
  for (register long long i = (1); i <= (len); ++i)
    ans = ans * qpow(pri[i], c[B][i] - c[A][i] - c[B - A][i]) % skc;
  return ans;
}
signed main() {
  long long l, r;
  cin >> n >> skc >> l >> r;
  prep();
  long long ans = 0;
  for (register long long i = (0); i <= (n - l); ++i) {
    long long ts = C(((n - i - l) / 2), n - i);
    if ((n - i - r - 1) >= 0) ts -= C(((n - i - r - 1) / 2), n - i);
    ts = (ts % skc + skc) % skc;
    upd(ans, C(i, n) * ts % skc);
  }
  cout << ans << '\n';
  return 0;
}
