#include <bits/stdc++.h>
using namespace std;
long long inv[100010], fac[100010], p[100010], t[100010][20];
int n, l, r, P, tot, Phi;
int phi(int k) {
  int i, s;
  s = k;
  for (i = 2; i * i <= k; i++) {
    if (k % i == 0) s = s / i * (i - 1);
    while (k % i == 0) k /= i;
  }
  if (k > 1) s = s / k * (k - 1);
  return s;
}
long long qpow(long long a, long long b, long long mod) {
  long long res = 1;
  while (b) {
    if (b & 1) res = res * a % mod;
    b >>= 1;
    a = a * a % mod;
  }
  return res;
}
void init() {
  long long x = P;
  Phi = phi(P);
  for (int i = 2; (long long)i * i <= x; i++) {
    if (x % i) continue;
    while (x % i == 0) x /= i;
    p[++tot] = i;
  }
  if (x > 1) p[++tot] = x;
  inv[0] = inv[1] = 1;
  fac[0] = fac[1] = 1;
  for (int i = 2; i < 100010; i++) {
    x = i;
    for (int j = 1; j <= tot; j++) {
      t[i][j] = t[i - 1][j];
      if (x % p[j]) continue;
      while (x % p[j] == 0) x /= p[j], t[i][j]++;
    }
    fac[i] = fac[i - 1] * x % P;
    inv[i] = qpow(fac[i], Phi - 1, P);
  }
}
long long C(int n, int m) {
  long long res = 0;
  if (n < m || n < 0) return 0;
  res = fac[n] * inv[m] % P * inv[n - m] % P;
  for (int i = 1; i <= tot; i++)
    res = res * qpow(p[i], t[n][i] - t[m][i] - t[n - m][i], P) % P;
  return res;
}
int main() {
  scanf("%d%d%d%d", &n, &P, &l, &r);
  init();
  long long ans = 0;
  for (int i = 0; i <= n; i++) {
    int m = n - i;
    ans = (ans + C(n, i) *
                     (-C(m, (m + min(r, m) >> 1) + 1) + C(m, m + l + 1 >> 1)) %
                     P) %
          P;
  }
  printf("%I64d\n", ans);
  return 0;
}
