#include <bits/stdc++.h>
using namespace std;
vector<pair<pair<int, int>, vector<int>>> lst;
vector<int> fact;
pair<int, vector<int>> tmp, _tmp;
void init(int p) {
  fact.clear();
  int i;
  for (i = 2; i * i <= p; i++) {
    if (p % i == 0) {
      fact.push_back(i);
      while (p % i == 0) p /= i;
    } else
      ;
  }
  if (p != 1)
    fact.push_back(p);
  else
    ;
}
long long calc(int n, int m, int a, int b, int p) {
  int i, x, y, j;
  tmp.first = lst[n].first.first * (long long)lst[m].first.second % p;
  tmp.second.clear();
  for (i = 0; i < fact.size(); i++) {
    tmp.second.push_back(lst[n].second[i] - lst[m].second[i]);
  }
  _tmp = tmp;
  int a1 = (n - m + a) / 2;
  int a2 = (n - m - a) / 2;
  int b1 = (n - m + b) / 2;
  int b2 = (n - m - b) / 2;
  for (i = 0; i < fact.size(); i++) {
    if (a1 >= 0 && a2 >= 0)
      tmp.second[i] -= lst[a1].second[i] + lst[a2].second[i];
    if (b1 >= 0 && b2 >= 0)
      _tmp.second[i] -= lst[b1].second[i] + lst[b2].second[i];
  }
  if (a1 < 0 || a2 < 0)
    x = 0;
  else {
    tmp.first = tmp.first * (long long)lst[a1].first.second % p *
                (long long)lst[a2].first.second % p;
    for (x = tmp.first, i = 0; i < fact.size(); i++) {
      for (j = tmp.second[i]; j > 0; j--) {
        x = (long long)x * fact[i] % p;
      }
    }
  }
  if (b1 < 0 || b2 < 0)
    y = 0;
  else {
    _tmp.first = _tmp.first * (long long)lst[b1].first.second % p *
                 (long long)lst[b2].first.second % p;
    for (y = _tmp.first, i = 0; i < fact.size(); i++) {
      for (j = _tmp.second[i]; j > 0; j--) {
        y = (long long)y * fact[i] % p;
      }
    }
  }
  return ((x - y) % p + (long long)p) % p;
}
void exgcd(int &x, int &y, int a, int b, int p) {
  if (b == 0) {
    y = 0;
    x = 1;
    return;
  }
  exgcd(x, y, b, a % b, p);
  int _x = x;
  x = y;
  y = ((_x - (a / b) * (long long)x % p) % p + (long long)p) % p;
}
void mklst(int n, int p) {
  int i, k, j, x, y;
  lst.clear();
  lst.resize(1);
  lst[0].first = {1, 1};
  lst[0].second.clear();
  lst[0].second.resize(fact.size(), 0);
  for (i = 1; i <= n; i++) {
    lst.push_back(lst.back());
    k = i;
    for (j = fact.size() - 1; ~j; j--) {
      for (; k % fact[j] == 0; k /= fact[j], lst[i].second[j]++)
        ;
    }
    k = (long long)k * lst.back().first.first % p;
    exgcd(x, y, k, p, p);
    lst[i].first = {k, x};
  }
}
int main() {
  int n, l, r, p;
  scanf("%d%d%d%d", &n, &p, &l, &r);
  init(p);
  long long sum = 0LL;
  mklst(n, p);
  int m, nl, nr;
  for (m = 0; m <= n; m++) {
    if ((n - m - l) & 1)
      nl = l + 1;
    else
      nl = l;
    if ((n - m - r) & 1)
      nr = r - 1;
    else
      nr = r;
    if (nl > nr)
      ;
    else {
      sum += calc(n, m, nl, nr + 2, p);
      sum %= p;
    }
  }
  printf("%lld\n", sum);
  return 0;
}
