#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
void Min(T &a, U b) {
  if (a > b) a = b;
}
template <class T, class U>
void Max(T &a, U b) {
  if (a < b) a = b;
}
long long pow(long long a, int b, int c) {
  long long ans = 1;
  while (b) {
    if (b & 1) ans = ans * a % c;
    a = 1LL * a * a % c;
    b >>= 1;
  }
  return ans;
}
int f[21][100010], c[21][100010];
vector<pair<int, int> > v;
vector<int> mo;
int cal(int n, int m, int i) {
  int w = c[i][n] - c[i][m] - c[i][n - m], q = mo[i];
  if (w >= v[i].second) return 0;
  long long ans = 1LL * f[i][m] * f[i][n - m] % q;
  ans = pow(ans, q - q / v[i].first - 1, q) * f[i][n] % q;
  return ans * pow(v[i].first, w, q) % q;
}
long long ex_gcd(long long a, long long b, long long &first,
                 long long &second) {
  if (b == 0) {
    first = 1, second = 0;
    return a;
  }
  long long x1, y1, d = ex_gcd(b, a % b, x1, y1);
  first = y1;
  second = x1 - a / b * first;
  return d;
}
long long cal(int n, int m) {
  if (m < 0) return 0;
  if (m == 0) return 1;
  int a1 = 1, b1 = 0;
  for (int i = 0; i < v.size(); i++) {
    long long a = mo[i];
    long long b = cal(n, m, i);
    long long first, second;
    long long d = ex_gcd(a, a1, first, second);
    long long bb = a1 / d;
    first *= (b1 - b) / d;
    first %= bb;
    if (first < 0) first += bb;
    b = a * first + b;
    a = a * a1;
    b %= a;
    a1 = a, b1 = b;
  }
  return b1;
}
int main() {
  int i, m = 0, j, k, K, T, n;
  int l, r, P;
  scanf("%d%d%d%d", &n, &P, &l, &r);
  K = P;
  for (int i = 2; i < 100010 << 1; i++) {
    if (1LL * i * i > P) break;
    if (K % i == 0) {
      k = 0;
      j = 1;
      while (K % i == 0) K /= i, k++, j *= i;
      v.push_back({i, k});
      mo.push_back(j);
    }
  }
  if (K > 1) v.push_back({K, 1}), mo.push_back(K);
  for (int i = 0; i < v.size(); i++) {
    int first = v[i].first, second = v[i].second, q = mo[i];
    f[i][0] = 1;
    for (int j = 1; j < 100010; j++) {
      K = j;
      k = 0;
      while (K % first == 0) K /= first, k++;
      f[i][j] = 1LL * f[i][j - 1] * K % q;
      c[i][j] = c[i][j - 1] + k;
    }
  }
  long long ans = 0;
  for (int i = 0; i < n + 1; i++) {
    m = n - i;
    if (l > m) break;
    int second = min(r, m);
    if ((second & 1) != (m & 1)) second--;
    int first = l;
    if ((first & 1) != (m & 1)) first++;
    if (first <= second) {
      long long w = (cal(m, (m - first) / 2) - cal(m, (m - second) / 2 - 1)) *
                    cal(n, i) % P;
      ans += w;
    }
  }
  ans %= P;
  if (ans < 0) ans += P;
  printf("%d\n", ans);
  return 0;
}
