#include <bits/stdc++.h>
using namespace std;
using ll = long long;
static const ll N = 1e5 + 10;
static const ll P = 11;
ll n, p, l, r;
ll t = 0;
vector<ll> prime(P);
vector<ll> fac(N);
vector<ll> inv(N);
vector<ll> val(N);
vector<vector<ll>> vp(P, vector<ll>(N));
vector<vector<ll>> po(P, vector<ll>(N));
inline ll modPow(ll a, ll pow) {
  ll result = 1;
  while (pow) {
    if (pow & 1) {
      result = (result * a) % p;
    }
    pow >>= 1;
    a = (a * a) % p;
  }
  return result;
}
inline void getNPLR() { cin >> n >> p >> l >> r; }
inline void fillTables() {
  ll num = p;
  for (ll i = 2; i * i <= num; i++) {
    if (num % i == 0) {
      while (num % i == 0) {
        num /= i;
      }
      prime[t++] = i;
    }
  }
  if (num > 1) {
    prime[t++] = num;
  }
  ll phi = p;
  for (ll i = 0; i < t; i++) {
    phi = (phi / prime[i]) * (prime[i] - 1);
  }
  fac[0] = 1;
  for (ll i = 1; i <= n; i++) {
    val[i] = i;
    for (ll j = 0; j < t; j++) {
      vp[j][i] = vp[j][i - 1];
      while (val[i] % prime[j] == 0) {
        val[i] /= prime[j];
        vp[j][i]++;
      }
    }
    fac[i] = (fac[i - 1] * val[i]) % p;
  }
  inv[n] = modPow(fac[n], phi - 1);
  for (ll i = n - 1; i >= 0; i--) {
    inv[i] = (inv[i + 1] * val[i + 1]) % p;
  }
  for (ll i = 0; i < t; i++) {
    po[i][0] = 1;
    for (ll j = 1; j <= vp[i][n]; j++) {
      po[i][j] = (po[i][j - 1] * prime[i]) % p;
    }
  }
}
inline ll choose(ll a, ll b) {
  if (b > a || 0 > b) {
    return 0;
  }
  ll result = (((fac[a] * inv[a - b]) % p) * inv[b]) % p;
  for (ll i = 0; i < t; i++) {
    result = (result * po[i][vp[i][a] - vp[i][a - b] - vp[i][b]]) % p;
  }
  return result;
}
int main(int argc, char const* argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  getNPLR();
  fillTables();
  ll res = 0;
  for (ll i = 0; i <= n; i++) {
    ll ls = (n - i + l + 1) / 2;
    ll rs = (n - i + r) / 2;
    res += choose(n, i) * (choose(n - i, ls) - choose(n - i, rs + 1));
    res %= p;
  }
  if (res < 0) {
    res += p;
  }
  cout << res << "\n";
  return 0;
}
