#include <bits/stdc++.h>
using namespace std;
int IN() {
  int c, f, x;
  while (!isdigit(c = getchar()) && c != '-')
    ;
  c == '-' ? (f = 1, x = 0) : (f = 0, x = c - '0');
  while (isdigit(c = getchar())) x = (x << 1) + (x << 3) + c - '0';
  return !f ? x : -x;
}
const int N = 100000 + 19;
int A[N], B[N], C[N];
int n, p, l, r, ans, m, t, x, y;
vector<pair<int, int> > V;
void exgcd(int a, int b, long long &x, long long &y) {
  if (!b) {
    x = 1, y = 0;
    return;
  }
  exgcd(b, a % b, x, y);
  long long tmp = x;
  x = y;
  y = tmp - a / b * y;
}
int inv(int a) {
  long long x, y;
  exgcd(a, p, x, y);
  return (0ll + x + p) % p;
}
struct num {
  int val;
  vector<int> c;
  num() {}
  num(int x) {
    c.resize(m);
    for (int i = 0; i < m; i++) {
      while (x % V[i].first == 0) x /= V[i].first, c[i]++;
    }
    val = x;
  }
  int value() {
    int res = val;
    for (int i = 0; i < m; i++)
      for (int j = 0; j < c[i]; j++) res = 1ll * res * V[i].first % p;
    return res;
  }
} T[N], tmp;
num operator*(const num &A, const num &B) {
  static num C;
  C.val = 1ll * A.val * B.val % p;
  C.c.resize(m);
  for (int i = 0; i < m; i++) C.c[i] = A.c[i] + B.c[i];
  return C;
}
num operator/(const num &A, const num &B) {
  static num C;
  C.val = 1ll * A.val * inv(B.val) % p;
  C.c.resize(m);
  for (int i = 0; i < m; i++) C.c[i] = A.c[i] - B.c[i];
  return C;
}
void work(int n, int m) {
  for (; x < n; x++) tmp = tmp * T[x + 1] / T[x + 1 - y];
  for (; y < m; y++) tmp = tmp * T[x - y] / T[y + 1];
}
void Init() {
  int x = p;
  for (int i = 2; 1ll * i * i <= x; i++)
    if (x % i == 0) {
      pair<int, int> tmp = make_pair(i, 0);
      while (x % i == 0) x /= i, tmp.second++;
      V.push_back(tmp);
    }
  if (x > 1) V.push_back(make_pair(x, 1));
  m = V.size();
  for (int i = 1; i < n + 1; i++) T[i] = num(i);
}
int main() {
  n = IN(), p = IN(), l = IN(), r = IN();
  Init();
  A[0] = 1;
  tmp = 1;
  x = n, y = 0;
  for (int c = 1; c < n + 1; c++) {
    work(n, c);
    A[c] = tmp.value();
  }
  for (t = 0; t <= n && t < (t + l + 1) / 2; t++)
    ;
  B[t] = 1;
  tmp = 1;
  x = t;
  y = (t + l + 1) / 2;
  for (int c = t + 1; c < n + 1; c++) {
    work(c, (c + l + 1) / 2);
    B[c] = tmp.value();
  }
  for (t = 0; t <= n && t < (t + r) / 2 + 1; t++)
    ;
  C[t] = 1;
  tmp = 1;
  x = t;
  y = (t + r) / 2 + 1;
  for (int c = t + 1; c < n + 1; c++) {
    work(c, (c + r) / 2 + 1);
    C[c] = tmp.value();
  }
  for (int c = 0; c < n + 1; c++) {
    ans = (ans + 1ll * A[c] * (0ll + B[c] - C[c] + p)) % p;
  }
  printf("%d\n", ans);
}
