#include <bits/stdc++.h>
using namespace std;
long long n, p, l, r;
long long p0[25], pu[25], re[25];
long long mul[25][200005];
long long g[200005][25];
int cnt = 0;
void make_init() {
  long long tempp = p;
  for (long long i = 2; i * i <= p; i++) {
    if (p % i == 0) {
      cnt++, p0[cnt] = i, pu[cnt] = 1;
      while (p % i == 0) pu[cnt] *= i, p /= i;
    }
  }
  if (p != 1) cnt++, p0[cnt] = pu[cnt] = p;
  p = tempp;
}
void init() {
  for (long long i = 1; i <= cnt; i++) {
    mul[i][0] = 1;
    for (long long j = 1; j <= pu[i] && j <= 100000; j++) {
      if (j % p0[i])
        mul[i][j] = mul[i][j - 1] * j % pu[i];
      else
        mul[i][j] = mul[i][j - 1];
    }
  }
}
long long pow_mul(long long x, long long y, long long mode) {
  long long ret = 1;
  while (y) {
    if (y & 1) ret = ret * x % mode;
    x = x * x % mode, y >>= 1;
  }
  return ret;
}
void ex_gcd(long long a, long long b, long long &x, long long &y) {
  if (!b) {
    x = 1;
    y = 0;
    return;
  }
  ex_gcd(b, a % b, x, y);
  long long t = x;
  x = y, y = t - (a / b) * x;
}
long long get_inv(long long x, long long y) {
  long long xx, yy;
  ex_gcd(x, y, xx, yy);
  return (xx % y + y) % y;
}
long long calp(long long x, long long i) {
  long long ret = 0;
  x /= p0[i];
  while (x) ret += x, x /= p0[i];
  return ret;
}
long long calc(long long x, long long i) {
  if (g[x][i]) return g[x][i];
  if (!x) return 1;
  if (pu[i] == 4)
    return g[x][i] = pow_mul(3, x / pu[i], pu[i]) * mul[i][x % pu[i]] % pu[i] *
                     calc(x / p0[i], i) % pu[i];
  else if (p0[i] == 2)
    return g[x][i] = mul[i][x % pu[i]] % pu[i] * calc(x / p0[i], i) % pu[i];
  else
    return g[x][i] = pow_mul(pu[i] - 1, x / pu[i], pu[i]) * mul[i][x % pu[i]] %
                     pu[i] * calc(x / p0[i], i) % pu[i];
}
long long ex_lucas(long long x, long long y, long long i) {
  long long mi = calp(x, i) - calp(y, i) - calp(x - y, i);
  return pow_mul(p0[i], mi, pu[i]) * calc(x, i) % pu[i] *
         get_inv(calc(y, i), pu[i]) % pu[i] * get_inv(calc(x - y, i), pu[i]) %
         pu[i];
}
long long china() {
  long long ans = 0;
  for (int i = 1; i <= cnt; i++) {
    long long pp = p / pu[i];
    long long xx, yy;
    ex_gcd(pp, pu[i], xx, yy);
    xx = (xx % pu[i] + pu[i]) % pu[i];
    ans = (ans + xx * re[i] % p * pp % p) % p;
  }
  return ans;
}
long long solve(long long x, long long y) {
  for (int i = 1; i <= cnt; i++) re[i] = ex_lucas(x, y, i);
  return china();
}
int main() {
  scanf("%lld%lld%lld%lld", &n, &p, &l, &r);
  make_init(), init();
  long long S = 0;
  for (long long i = 0; i <= n; i++) {
    if (n - i < l) continue;
    long long v1 = solve(n - i, (n - i - l) / 2);
    long long v2;
    if (n - i - r < 1)
      v2 = 0;
    else
      v2 = solve(n - i, (n - i - r - 1) / 2);
    long long v3 = solve(n, i);
    S = (S + (v1 + p - v2) % p * v3 % p) % p;
  }
  printf("%lld\n", S);
  return 0;
}
