#include <bits/stdc++.h>
using namespace std;
bool debug = 0;
int n, m, k;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
string direc = "RDLU";
long long ln, lk, lm;
void etp(bool f = 0) {
  puts(f ? "YES" : "NO");
  exit(0);
}
void addmod(int &x, int y, int mod = 1000000007) {
  assert(y >= 0);
  x += y;
  if (x >= mod) x -= mod;
  assert(x >= 0 && x < mod);
}
void et() {
  puts("-1");
  exit(0);
}
long long fastPow(long long x, long long y, int mod = 1000000007) {
  long long ans = 1;
  while (y > 0) {
    if (y & 1) ans = (x * ans) % mod;
    x = x * x % mod;
    y >>= 1;
  }
  return ans;
}
long long gcd1(long long x, long long y) {
  long long z = y;
  while (x % y != 0) {
    z = x % y;
    x = y;
    y = z;
  }
  return z;
}
long long phi(long long x) {
  long long ans = x;
  for (long long i = 2; i * i <= x; i++) {
    if (x % i == 0) {
      ans = ans / i * (i - 1);
      while (x % i == 0) x /= i;
    }
  }
  if (x > 1) ans = ans / x * (x - 1);
  return ans;
}
int fac[100005], inv[100005], tc[100005][20];
vector<int> ps;
void initfac(int n, int P) {
  int tmp = P;
  for (int i = 2; (long long)i * i <= tmp; i++)
    if (tmp % i == 0) {
      while (tmp % i == 0) tmp /= i;
      ps.push_back(i);
    }
  if (tmp > 1) ps.push_back(tmp);
  fac[0] = inv[0] = 1;
  fac[1] = inv[1] = 1;
  int N = ps.size();
  long long Phi = phi(P);
  for (int i = 2; i <= n; i++) {
    tmp = i;
    for (int(j) = 0; (j) < (int)(N); (j)++) {
      tc[i][j] += tc[i - 1][j];
      if (tmp % ps[j] != 0) continue;
      while (tmp % ps[j] == 0) {
        tmp /= ps[j];
        tc[i][j]++;
      }
    }
    fac[i] = (long long)fac[i - 1] * tmp % P;
    inv[i] = fastPow(fac[i], Phi - 1, P);
  }
}
int C(int n, int m, int P) {
  if (n < m) return 0;
  if (m == 0) return 1;
  int ans = (long long)fac[n] * inv[m] % P * inv[n - m] % P;
  for (int(i) = 0; (i) < (int)(ps.size()); (i)++) {
    ans = (long long)ans *
          fastPow(ps[i], tc[n][i] - tc[m][i] - tc[n - m][i], P) % P;
  }
  return ans;
}
void fmain(int ID) {
  int n, p, l, r;
  scanf("%d%d%d%d", &n, &p, &l, &r);
  r = min(n, r);
  long long ans = 0;
  initfac(n, p);
  for (int i = 0; i <= n; i++) {
    int tn = n - i;
    int gg = C(n, i, p);
    int R = min(tn, r);
    int L = l;
    if (tn % 2 == 0) {
      if (R & 1) R--;
      if (L & 1) L++;
    } else {
      if (R % 2 == 0) R--;
      if (L % 2 == 0) L++;
    }
    if (R < L) continue;
    long long tmp = -C(tn, (tn - R) / 2 - 1, p) + C(tn, (tn - L) / 2, p);
    tmp = (tmp + p) % p;
    ans += (long long)gg * tmp % p;
    ans %= p;
  }
  printf("%lld\n", ans);
}
int main() {
  int t = 1;
  for (int(i) = 1; (i) <= (int)(t); (i)++) {
    fmain(i);
  }
  return 0;
}
