#include <bits/stdc++.h>
using namespace std;
const int N = 100010, M = 12;
long long ans;
int n, mod;
long long cm[M], cx[M], cy[M];
struct comb {
  int mod, phi, p, c, maxn;
  int cj[N], f[N], num[N], fi[N];
  int pow[40];
  int power(int x, int y) {
    int ret = 1;
    for (; y; y >>= 1, x = 1ll * x * x % mod) {
      if (y & 1) ret = 1ll * ret * x % mod;
    }
    return ret;
  }
  void prepare() {
    int i;
    maxn = n;
    cj[0] = 1;
    for (i = 1; i <= maxn; i++)
      cj[i] = (i % p == 0) ? cj[i - 1] : 1ll * cj[i - 1] * i % mod;
    phi = mod / p * (p - 1);
    for (i = 1; i <= maxn; i++) num[i] = num[i / p] + i / p;
    f[0] = 1;
    fi[0] = 1;
    for (i = 1; i <= maxn; i++) {
      if (i < mod)
        f[i] = 1ll * cj[i] * f[i / p] % mod;
      else
        f[i] =
            1ll * power(cj[mod], i / mod) * cj[i % mod] % mod * f[i / p] % mod;
      fi[i] = power(f[i], phi - 1);
    }
    pow[0] = 1;
    for (i = 1; i <= c - 1; i++) pow[i] = pow[i - 1] * p;
  }
  int C(int n, int m) {
    int x = num[n] - num[m] - num[n - m];
    if (x >= c) return 0;
    return 1ll * f[n] * fi[m] % mod * fi[n - m] % mod * pow[x] % mod;
  }
};
comb a[M];
int cnt;
long long C(int n, int m) {
  if (n < m) return 0;
  long long r1, r2, x;
  int i;
  r1 = a[1].C(n, m);
  for (i = 2; i <= cnt; i++) {
    r2 = a[i].C(n, m);
    x = cx[i] * (r2 - r1) % cm[i];
    r1 = (cm[i - 1] * x + r1) % cm[i];
    r1 = (r1 + cm[i]) % cm[i];
  }
  return r1;
}
void exgcd(long long a, long long b, long long &x, long long &y) {
  if (b == 0) {
    x = 1;
    y = 0;
    return;
  }
  exgcd(b, a % b, y, x);
  y -= a / b * x;
}
void prepare(int mod) {
  int i;
  for (i = 2; i * i <= mod; i++)
    if (mod % i == 0) {
      cnt++;
      a[cnt].p = i;
      a[cnt].mod = 1;
      while (mod % i == 0) {
        a[cnt].c++;
        a[cnt].mod *= i;
        mod /= i;
      }
      a[cnt].prepare();
    }
  if (mod > 1) {
    cnt++;
    a[cnt].p = mod;
    a[cnt].c = 1;
    a[cnt].mod = mod;
    a[cnt].prepare();
  }
  cm[1] = a[1].mod;
  long long x, y;
  for (i = 2; i <= cnt; i++) {
    exgcd(cm[i - 1], a[i].mod, x, y);
    cm[i] = a[i].mod * cm[i - 1];
    cx[i] = (x % a[i].mod + a[i].mod) % a[i].mod;
  }
}
int main() {
  int L, R;
  int i, j, l, r, m;
  scanf("%d%d%d%d", &n, &mod, &L, &R);
  if (mod == 1) {
    printf("0\n");
    return 0;
  }
  prepare(mod);
  for (i = 0; i <= n; i++) {
    m = n - i;
    l = (m + L + 1) / 2;
    r = (m + R) / 2;
    r = min(r, m);
    if (l > r) continue;
    ans = (ans + C(n, m) * (C(m, l) - C(m, r + 1))) % mod;
  }
  ans = (ans + mod) % mod;
  printf("%d\n", (int)ans);
}
