#include <bits/stdc++.h>
using namespace std;
void factorize(long long v, std::map<long long, int> &result) {
  long long p = 2;
  while (v > 1 && p * p <= v) {
    int cnt = 0;
    while (v % p == 0) {
      cnt++;
      v /= p;
    }
    if (cnt > 0) {
      if (result.count(p) == 0) {
        result[p] = 0;
      }
      result[p] += cnt;
    }
    p += p == 2 ? 1 : 2;
  }
  if (v > 1) {
    if (result.count(v) == 0) {
      result[v] = 0;
    }
    result[v] += 1;
  }
}
long long int ex_gcd(long long int x, long long int y, long long int &a,
                     long long int &b) {
  if (y == 0) {
    a = 1;
    b = 0;
    return x;
  }
  long long int q = x / y;
  long long int r = x % y;
  long long int res = ex_gcd(y, r, a, b);
  long long int tmp = a - q * b;
  a = b;
  b = tmp;
  return res;
}
const int N = 123456;
int n;
long long int p;
vector<long long int> q;
vector<int> e;
long long int fact[N];
long long int invfact[N];
vector<int> fact_e[N];
void init(void) {
  map<long long int, int> factor;
  factorize(p, factor);
  for (map<long long int, int>::iterator it = factor.begin();
       it != factor.end(); ++it) {
    q.push_back(it->first);
    e.push_back(it->second);
  }
  int l = e.size();
  fact_e[0] = vector<int>(l, 0);
  fact[0] = invfact[0] = 1;
  for (int i = (int)(1); i < (int)(N); i++) {
    int v = i;
    fact_e[i] = fact_e[i - 1];
    for (int j = (int)(0); j < (int)(l); j++) {
      while (v % q[j] == 0) {
        fact_e[i][j] += 1;
        v /= q[j];
      }
    }
    fact[i] = fact[i - 1] * v % p;
    long long int dummy2;
    long long int dummy = ex_gcd(fact[i], p, invfact[i], dummy2);
    assert(dummy == 1);
    invfact[i] = (invfact[i] % p + p) % p;
  }
}
long long int tri_comb(int x, int y) {
  long long int t = 1;
  int len = e.size();
  t = (fact[n] * invfact[x]) % p;
  t = t * invfact[y] % p;
  t = t * invfact[n - x - y] % p;
  vector<int> es(len);
  for (int i = (int)(0); i < (int)(len); i++) {
    es[i] = fact_e[n][i] - fact_e[x][i] - fact_e[y][i] - fact_e[n - x - y][i];
    for (int j = (int)(0); j < (int)(es[i]); j++) {
      t = t * q[i] % p;
    }
  }
  return t;
}
long long int calc(int l) {
  long long int tot = 0;
  for (int i = (int)(0); i < (int)(n - l + 1); i++) {
    if ((n + i + l) % 2 == 0) {
      tot = (tot + tri_comb(i, (n - i - l) / 2)) % p;
    }
  }
  return tot;
}
int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int l, r;
  cin >> n >> p >> l >> r;
  init();
  cout << (calc(l) + calc(l + 1) - calc(r + 1) - calc(r + 2) + 2 * p) % p
       << "\n";
}
