#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int n, p, l, r, pri[30], cnt;
long long d[N][30], fac[N], inv[N];
long long POW(long long x, long long k) {
  long long a = 1;
  while (k) {
    if (k & 1) a = a * x % p;
    x = x * x % p;
    k >>= 1;
  }
  return a;
}
void init() {
  int s = p, res = p;
  for (int i = 2; i * i <= p; i++) {
    if (s % i == 0) {
      pri[cnt++] = i;
      res = res / i * (i - 1);
      while (s % i == 0) s /= i;
    }
  }
  if (s > 1) {
    pri[cnt++] = s;
    res = res / s * (s - 1);
  }
  for (int i = 2; i <= n; i++) {
    for (int j = 0; j < cnt; j++) {
      d[i][j] = d[i - 1][j];
      int tmp = i;
      while (tmp % pri[j] == 0) {
        d[i][j]++;
        tmp /= pri[j];
      }
    }
  }
  inv[0] = inv[1] = fac[0] = fac[1] = 1;
  for (int i = 2; i <= n; i++) {
    s = i;
    for (int j = 0; j < cnt; j++) {
      while (s % pri[j] == 0) s /= pri[j];
    }
    fac[i] = fac[i - 1] * s % p;
    inv[i] = POW(fac[i], res - 1);
  }
}
long long C(int n, int m) {
  if (n < m) return 0;
  if (!m) return 1;
  long long res = (fac[n] * inv[m] % p) * inv[n - m] % p;
  for (int i = 0; i < cnt; i++) {
    res = res * POW(pri[i], d[n][i] - d[m][i] - d[n - m][i]) % p;
  }
  return res;
}
int main() {
  int l, r;
  cin >> n >> p >> l >> r;
  init();
  long long ans = 0;
  for (int i = 0; i <= n; i++) {
    ans =
        (ans + C(n, i) *
                   (C(i, (i + l + 1) / 2) - C(i, (i + min(i, r)) / 2 + 1) + p) %
                   p) %
        p;
  }
  cout << ans << endl;
  return 0;
}
