#include <bits/stdc++.h>
using namespace std;
long long MOD;
vector<vector<long long> > mul(vector<vector<long long> > A,
                               vector<vector<long long> > B) {
  vector<vector<long long> > C(A.size(), vector<long long>(B[0].size()));
  for (int i = 0; i < A.size(); i++) {
    for (int j = 0; j < B[0].size(); j++) {
      for (int k = 0; k < A[0].size(); k++) {
        C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % MOD;
      }
      C[i][j] %= MOD;
    }
  }
  return C;
}
vector<vector<long long> > pow(vector<vector<long long> > A, long long n) {
  vector<vector<long long> > B(A.size(), vector<long long>(A.size()));
  for (int i = 0; i < A.size(); i++) {
    B[i][i] = 1;
  }
  while (n > 0) {
    if (n & 1) B = mul(B, A);
    A = mul(A, A);
    n >>= 1;
  }
  return B;
}
int main() {
  long long le, ri, k;
  cin >> MOD >> le >> ri >> k;
  long long p = 1;
  for (int i = 1; i <= 1000000; i++) {
    long long j = ri / i;
    if (i > p && (ri / i - (le - 1) / i >= k)) p = i;
    if (j > p && (ri / j - (le - 1) / j >= k)) p = j;
  }
  vector<vector<long long> > A(2, vector<long long>(2));
  A[0][0] = A[0][1] = 1;
  A[1][0] = 1;
  A[1][1] = 0;
  A = pow(A, p);
  cout << A[1][0] % MOD << endl;
  return 0;
}
