#include <bits/stdc++.h>
using namespace std;
class Integer {
 public:
  static void SetModulo(int mod) {
    mod_ = mod;
    phi_ = mod;
    divisors_.clear();
    for (int i = 2; i * i <= mod; i += 1) {
      if (mod % i == 0) {
        divisors_.push_back(i);
        phi_ /= i;
        phi_ *= i - 1;
        while (mod % i == 0) {
          mod /= i;
        }
      }
    }
    if (mod > 1) {
      divisors_.push_back(mod);
      phi_ /= mod;
      phi_ *= mod - 1;
    }
  }
  Integer() {}
  Integer(int n) : n_(n), exponents_(divisors_.size()) {
    for (int idx = 0; idx < (int)divisors_.size(); idx += 1) {
      while (n % divisors_[idx] == 0) {
        exponents_[idx] += 1;
        n /= divisors_[idx];
      }
    }
    n_ = n % mod_;
  }
  Integer& operator*=(const Integer& rhs) {
    for (int i = 0; i < (int)exponents_.size(); i += 1) {
      exponents_[i] += rhs.exponents_[i];
    }
    n_ = (int64_t)n_ * rhs.n_ % mod_;
    return *this;
  }
  Integer& operator/=(const Integer& rhs) {
    for (int i = 0; i < (int)exponents_.size(); i += 1) {
      exponents_[i] -= rhs.exponents_[i];
    }
    n_ = (int64_t)n_ * FindInverse(rhs.n_) % mod_;
    return *this;
  }
  int64_t Get() const {
    int64_t answer = n_;
    for (int i = 0; i < (int)divisors_.size(); i += 1) {
      answer = answer * Pow(divisors_[i], exponents_[i]) % mod_;
    }
    return answer;
  }
  friend Integer operator*(const Integer& lhs, const Integer& rhs) {
    return Integer(lhs) *= rhs;
  }
  friend Integer operator/(const Integer& lhs, const Integer& rhs) {
    return Integer(lhs) /= rhs;
  }

 private:
  int n_;
  vector<int> exponents_;
  static int mod_, phi_;
  static vector<int> divisors_;
  static int Pow(int base, int exponent) {
    int answer = 1;
    while (exponent) {
      if (exponent & 1) {
        answer = (int64_t)answer * base % mod_;
      }
      base = (int64_t)base * base % mod_;
      exponent >>= 1;
    }
    return answer;
  }
  static int FindInverse(int number) { return Pow(number, phi_ - 1); }
};
int Integer::mod_, Integer::phi_;
vector<int> Integer::divisors_;
int main() {
  int n, mod, l_bound, r_bound;
  cin >> n >> mod >> l_bound >> r_bound;
  Integer::SetModulo(mod);
  vector<Integer> factorial(n + 1);
  factorial[0] = Integer(1);
  for (int i = 1; i <= n; i += 1) {
    factorial[i] = factorial[i - 1] * Integer(i);
  }
  vector<Integer> inverse_factorial(n + 1);
  inverse_factorial[n] = Integer(1) / factorial[n];
  for (int i = n - 1; i >= 0; i -= 1) {
    inverse_factorial[i] = inverse_factorial[i + 1] * Integer(i + 1);
  }
  function<int64_t(int, int)> Binomial = [&](int n, int m) {
    if (m < 0) {
      return (int64_t)0;
    }
    return (factorial[n] * inverse_factorial[n - m] * inverse_factorial[m])
        .Get();
  };
  int64_t answer = 0;
  for (int non_vip = l_bound; non_vip <= n; non_vip += 1) {
    int64_t fixed_answer = Binomial(n, non_vip);
    fixed_answer = fixed_answer *
                   (Binomial(non_vip, (non_vip - l_bound) / 2) -
                    Binomial(non_vip, (non_vip - r_bound + 1) / 2 - 1) + mod) %
                   mod;
    answer += fixed_answer;
    if (answer >= mod) {
      answer -= mod;
    }
  }
  cout << answer << endl;
  return 0;
}
