#include <bits/stdc++.h>
using namespace std;
int lg(long long n) {
  assert(n > 0);
  int ans = -1;
  while (n) {
    ans++;
    n >>= 1;
  }
  return ans;
}
void solve() {
  long long N, K, L, R;
  cin >> N >> L >> R >> K;
  long long ans = -1;
  long long x = R >= L ? R - L + 1 : R + N - L + 1;
  if (x == N) x = 0;
  for (long long cycs = K; cycs;) {
    long long ub = K / cycs, lb = K / (cycs + 1) + 1;
    ub = min(ub, 2 * N);
    lb = max(lb, N);
    ub = min(ub, (K - x) / cycs);
    ub = min(ub, (K + 2 * N - 2 * x + 1) / (cycs + 1));
    lb = max(lb, (K - 2 * x + cycs - 1) / cycs);
    if (ub >= lb) {
      ans = max(ans, ub);
    }
    cycs = K / (K / cycs + 1);
  }
  x = R >= L ? R - L + 1 : R + N - L + 1;
  if (x <= K && K <= 2 * x) {
    ans = max(ans, min(2 * N, N + N - x + K - x + 1));
  }
  cout << (ans == -1 ? ans : ans - N) << '\n';
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) solve();
  return 0;
}
