#include <bits/stdc++.h>
using namespace std;
const int MN = 100010;
vector<int> pr, pchk;
void Sieve() {
  pchk = vector<int>(MN, 0);
  for (int i = 2; i < MN; i++) {
    if (!pchk[i]) {
      pr.push_back(i);
    }
    for (int j = 0; j < pr.size() && i * pr[j] < MN; j++) {
      pchk[i * pr[j]] = 1;
      if (i % pr[j] == 0) break;
    }
  }
}
int po(int x, int n, int m) {
  int ret = 1;
  while (n) {
    if (n & 1) ret = 1LL * ret * x % m;
    x = 1LL * x * x % m;
    n >>= 1;
  }
  return ret;
}
int inv(int x, int p, int m) { return po(x, m - m / p - 1, m); }
int N, P, L, R;
vector<pair<int, int> > fact;
map<int, vector<int> > prec;
void Fact() {
  int n = P;
  for (int i = 0; i < pr.size() && pr[i] <= n; i++) {
    if (n % pr[i] == 0) {
      int cnt = 0;
      while (n % pr[i] == 0) {
        cnt++;
        n /= pr[i];
      }
      fact.push_back(pair<int, int>(pr[i], cnt));
    }
  }
  if (n != 1) fact.push_back(pair<int, int>(n, 1));
}
void Prec() {
  for (int i = 0; i < fact.size(); i++) {
    int p = fact[i].first;
    int t = fact[i].second;
    int m = po(p, t, 2e9 + 1);
    prec[p].resize(MN);
    prec[p][0] = 1;
    for (int j = 1; j < MN; j++) {
      prec[p][j] = 1LL * prec[p][j - 1] * (j % p == 0 ? 1 : j) % m;
    }
  }
}
int calc3(int n, int p, int m) {
  if (n == 0) return 0;
  int ret = 0;
  ret += n / p;
  ret += calc3(n / p, p, m);
  return ret;
}
long long calc2(int n, int p, int m) {
  if (n == 0) return 1;
  return 1LL * prec[p][n] * calc2(n / p, p, m) % m;
}
long long calc1(int n, int k, int p, int m) {
  long long x = calc3(n, p, m) - calc3(n - k, p, m) - calc3(k, p, m);
  long long y = 1LL * calc2(n, p, m) * inv(calc2(n - k, p, m), p, m) % m *
                inv(calc2(k, p, m), p, m) % m;
  return 1LL * y * po(p, x, m) % m;
}
long long comb(int n, int k) {
  long long R = 0, M = 1;
  for (int i = 0; i < fact.size(); i++) {
    int p = fact[i].first;
    int t = fact[i].second;
    int m = po(p, t, 2e9 + 1);
    long long r = calc1(n, k, p, m);
    long long a = 1LL * (r + m - R % m) * inv(M, p, m) % m;
    R += 1LL * a * M % (m * M);
    R %= (m * M);
    M *= m;
  }
  return R;
}
int main() {
  cin >> N >> P >> L >> R;
  Sieve();
  Fact();
  Prec();
  long long ans = 0;
  for (int c = 0; c <= N; c++) {
    long long tmp = 0;
    if ((N - c) % 2 == 0) {
      if (N - c >= (L % 2 == 0 ? L : L + 1))
        tmp += comb(N - c, (N - c) / 2 - (L % 2 == 0 ? L : L + 1) / 2);
      if (N - c >= (R % 2 == 0 ? R + 2 : R + 1))
        tmp -= comb(N - c, (N - c) / 2 - (R % 2 == 0 ? R + 2 : R + 1) / 2);
      tmp = (tmp % P + P) % P;
    }
    if ((N - c) % 2 == 1) {
      if (N - c >= (L % 2 == 1 ? L : L + 1))
        tmp += comb(N - c, (N - c) / 2 - (L % 2 == 1 ? L : L + 1) / 2);
      if (N - c >= (R % 2 == 1 ? R + 2 : R + 1))
        tmp -= comb(N - c, (N - c) / 2 - (R % 2 == 1 ? R + 2 : R + 1) / 2);
    }
    ans += 1LL * comb(N, c) * tmp % P;
    ans %= P;
  }
  cout << ans;
}
