#include <bits/stdc++.h>
using namespace std;
int n, p, l, r, t, m, a[50], c[100000 + 10][50], jic[100000 + 10],
    inv[100000 + 10], sum;
inline int quick_power(int a, int b) {
  int s = 1;
  for (; b; b >>= 1, a = 1ll * a * a % p)
    if (b & 1) s = 1ll * s * a % p;
  return s;
}
inline void init() {
  int i, j, w = p, z;
  for (t = p, i = 2; i * i <= t; ++i)
    if (t % i == 0)
      for (a[++m] = i, t /= i; t % i == 0; t /= i)
        ;
  if (t > 1) a[++m] = t;
  for (i = 1; i <= m; ++i) w = w / a[i] * (a[i] - 1);
  for (jic[0] = inv[0] = 1, i = 1; i <= 100000; ++i) {
    for (z = i, j = 1; j <= m; ++j)
      for (c[i][j] = c[i - 1][j]; z % a[j] == 0; z /= a[j], c[i][j]++)
        ;
    jic[i] = 1ll * jic[i - 1] * z % p, inv[i] = quick_power(jic[i], w - 1);
  }
}
inline int zuhe(int x, int y) {
  if (x < y) return 0;
  if (y == 0) return 1;
  int ans = 1ll * jic[x] * inv[y] % p * inv[x - y] % p;
  for (int i = 1; i <= m; ++i)
    ans = 1ll * ans * quick_power(a[i], c[x][i] - c[y][i] - c[x - y][i]) % p;
  return ans;
}
int main() {
  int i, j;
  scanf("%d%d%d%d", &n, &p, &l, &r);
  for (init(), i = 0; i <= n; ++i) {
    int len = n - i;
    sum = ((sum + 1ll *
                      (zuhe(len, l + len + 1 >> 1) -
                       zuhe(len, (min(len, r) + len >> 1) + 1)) *
                      zuhe(n, i)) %
               p +
           p) %
          p;
  }
  printf("%d", sum);
}
