#include <bits/stdc++.h>
using namespace std;
long long shin[25];
long long seto(void);
void ayano(long long x, char spliter = '\n');
int p, phip, phipm;
int prims[10], primdeg[10], primcnt = 0;
int kasumi(int a, int b);
int comb(int a, int b);
struct Num {
  int x, xinv, degs[10];
  Num(void) : x(1), xinv(1) {
    for (int i = 1; i <= primcnt; i++) this->degs[i] = 0;
  }
  Num(int y) {
    for (int i = 1; i <= primcnt; i++) {
      int ip = prims[i];
      int d = y / ip;
      this->degs[i] = 0;
      while (d * ip == y) this->degs[i]++, y = d, d = y / ip;
    }
    y %= p;
    this->x = y, this->xinv = kasumi(y, phipm);
  }
  Num(const Num& tn) : x(tn.x), xinv(tn.xinv) {
    for (int i = 1; i <= primcnt; i++) this->degs[i] = tn.degs[i];
  }
  int output(void) {
    int oans = this->x;
    for (int i = 1; i <= primcnt; i++)
      oans = 1ll * oans * kasumi(prims[i], this->degs[i]) % p;
    return oans;
  }
  friend Num operator*(const Num& lhs, const Num& rhs);
  friend Num operator/(const Num& lhs, const Num& rhs);
};
Num factors[100005];
int main(void) {
  int n, l, r;
  n = seto(), p = seto(), l = seto(), r = seto();
  if (p == 1) {
    ayano(0);
    return 0;
  }
  int tp = p;
  phip = p;
  for (int ip = 2; ip * ip <= tp; ip++) {
    int d = tp / ip;
    if (!(d * ip == tp)) continue;
    primcnt++, prims[primcnt] = ip, phip = phip / ip * (ip - 1);
    while (d * ip == tp) primdeg[primcnt]++, tp = d, d = tp / ip;
  }
  if (tp > 1)
    primcnt++, prims[primcnt] = tp, primdeg[primcnt] = 1,
               phip = phip / tp * (tp - 1);
  phipm = phip - 1;
  factors[0] = Num(1);
  for (int i = 1; i <= n; i++) factors[i] = Num(i) * factors[i - 1];
  long long ans = 0;
  for (int i = l; i <= n; i++) {
    int lb = l;
    ((lb ^ i) & 1) ? (lb++) : (0);
    int rb = min(i, r);
    ((rb ^ i) & 1) ? (rb--) : (0);
    if (lb > rb) continue;
    long long tans =
        1ll * comb(i, (i + lb) / 2) + p - comb(i, (i + rb + 2) / 2);
    (((tans) >= (p)) ? ((tans) -= (p)) : (0));
    tans = 1ll * tans * comb(n, i) % p;
    ans += tans, (((ans) >= (p)) ? ((ans) -= (p)) : (0));
  }
  ayano(ans);
  return 0;
}
int comb(int a, int b) {
  if (b > a) return 0;
  Num cansn = factors[a] / factors[b];
  cansn = cansn / factors[a - b];
  return cansn.output();
}
int kasumi(int a, int b) {
  int kans = 1;
  while (b)
    (b & 1) ? (kans = 1ll * kans * a % p) : (0), b >>= 1, a = 1ll * a * a % p;
  return kans;
}
Num operator*(const Num& lhs, const Num& rhs) {
  Num mans(lhs);
  mans.x = 1ll * mans.x * rhs.x % p;
  mans.xinv = 1ll * mans.xinv * rhs.xinv % p;
  for (int i = 1; i <= primcnt; i++) mans.degs[i] += rhs.degs[i];
  return mans;
}
Num operator/(const Num& lhs, const Num& rhs) {
  Num mans(lhs);
  mans.x = 1ll * mans.x * rhs.xinv % p;
  mans.xinv = 1ll * mans.xinv * rhs.x % p;
  for (int i = 1; i <= primcnt; i++) mans.degs[i] -= rhs.degs[i];
  return mans;
}
long long seto(void) {
  long long seto_x = 0;
  int symbol = 0;
  char ch = getchar();
  while (!isdigit(ch)) (ch == '-') ? (symbol = 1) : (0), ch = getchar();
  while (isdigit(ch)) (seto_x = seto_x * 10 + (ch - '0')), ch = getchar();
  return (symbol) ? (-seto_x) : (seto_x);
}
void ayano(long long ayano_x, char spliter) {
  if (!ayano_x) {
    putchar('0'), putchar(spliter);
    return;
  }
  if (ayano_x < 0) putchar('-'), ayano_x = -ayano_x;
  int ayano_len = 0;
  while (ayano_x) {
    long long ayano_d = ayano_x / 10;
    shin[ayano_len++] = ayano_x - ayano_d * 10;
    ayano_x = ayano_d;
  }
  while (ayano_len--) putchar(shin[ayano_len] + '0');
  putchar(spliter);
}
