#include <bits/stdc++.h>
using namespace std;
const int N = 100003;
int n, L, R, phi;
long long mod;
long long fac[N], inv[N];
int d[N][33];
int tot, p[N];
long long fpow(long long x, int y) {
  long long res = 1;
  while (y) {
    if (y & 1) res = res * x % mod;
    x = x * x % mod;
    y >>= 1;
  }
  return res;
}
void init() {
  fac[0] = inv[0] = 1;
  for (int i = 1; i <= n; i++) {
    int tmp = i;
    for (int j = 1; j <= tot; j++) {
      d[i][j] = d[i - 1][j];
      while (tmp % p[j] == 0) tmp /= p[j], d[i][j]++;
    }
    fac[i] = fac[i - 1] * tmp % mod;
    inv[i] = fpow(fac[i], phi - 1);
  }
}
long long C(int n, int m) {
  if (n < m) return 0;
  long long res = fac[n] * inv[m] % mod * inv[n - m] % mod;
  for (int i = 1; i <= tot; i++)
    res = res * fpow(p[i], d[n][i] - d[m][i] - d[n - m][i]) % mod;
  return res;
}
int main() {
  scanf("%d%I64d%d%d", &n, &mod, &L, &R);
  int tmp = mod;
  phi = mod;
  for (int i = 2; i * i <= tmp; i++)
    if (tmp % i == 0) {
      p[++tot] = i;
      phi = phi / i * (i - 1);
      while (tmp % i == 0) tmp /= i;
    }
  if (tmp != 1) p[++tot] = tmp, phi = phi / tmp * (tmp - 1);
  init();
  long long ans = 0;
  for (int i = 0; i <= n; i++) {
    long long res = (C(i, (i + L + 1) / 2) - C(i, (i + R) / 2 + 1) + mod) % mod;
    ans = (ans + res * C(n, i) % mod) % mod;
  }
  printf("%I64d", ans);
  return 0;
}
