#include <bits/stdc++.h>
using namespace std;
const int inf = 1.01e9;
const double eps = 1e-9;
int P;
const int N = 1e5 + 10;
int p[111], pp = 0;
struct num {
  vector<int> a;
  int r;
  num(int x) {
    a = vector<int>(pp);
    for (int i = 0; (i) < (pp); ++i) {
      while (x % p[i] == 0) {
        a[i]++;
        x /= p[i];
      }
    }
    r = x;
  }
  num() {
    a = vector<int>(pp);
    r = 0;
  }
};
inline num operator*(num A, num B) {
  num C;
  for (int i = 0; (i) < (pp); ++i) C.a[i] = A.a[i] + B.a[i];
  C.r = A.r * (long long)B.r % P;
  return C;
}
int rev(int a, int m) {
  if (a <= 1) return 1;
  return (1 - rev(m % a, a) * (long long)m) / a + m;
}
inline num operator/(num A, num B) {
  num C;
  for (int i = 0; (i) < (pp); ++i) C.a[i] = A.a[i] - B.a[i];
  C.r = A.r * (long long)rev(B.r, P) % P;
  return C;
}
num fact[N];
void init() {
  int mod = P;
  for (int i = 2; i * i <= mod; ++i)
    if (mod % i == 0) {
      p[pp++] = i;
      while (mod % i == 0) mod /= i;
    }
  if (mod > 1) p[pp++] = mod;
  fact[0] = num(1);
  for (int i = 1; i < N; ++i) {
    fact[i] = fact[i - 1] * num(i);
  }
}
int cnk(int n, int k) {
  if (k > n || k < 0) return 0;
  num R = fact[n] / (fact[k] * fact[n - k]);
  int ans = R.r;
  for (int i = 0; (i) < (pp); ++i)
    for (int j = 0; (j) < (R.a[i]); ++j) ans = (ans * (long long)p[i]) % P;
  return ans;
}
int main() {
  int n, l, r;
  scanf("%d%d%d%d", &n, &P, &l, &r);
  init();
  int ans = 0;
  for (int m = l; m <= n; ++m) {
    int R = min(m, r);
    if (m % 2 != R % 2) R--;
    int L = l;
    if (m % 2 != L % 2) L++;
    if (L > R) continue;
    int fst = cnk(m, (m - L) / 2);
    int lst = cnk(m, (m - R) / 2 - 1);
    ans = (ans + ((long long)fst + P - lst) * (long long)cnk(n, m)) % P;
  }
  printf("%d\n", ans);
  return 0;
}
