#include <bits/stdc++.h>
using namespace std;
const int maxc = 1000000000;
int main() {
  long long n, k, l, r;
  scanf("%lld%lld%lld%lld", &n, &l, &r, &k);
  long long d = r - l + 1;
  if (l > r) {
    d = n - l + 1 + r;
  }
  if (d == n) {
    long long ans = -1;
    for (long long i = 1; i * i <= k + 1; i++) {
      if (k % i == 0) {
        if (i >= n && i <= 2 * n) ans = max(ans, i - n);
        if (k / i >= n && k / i <= 2 * n) ans = max(ans, k / i - n);
      }
      if ((k + 1) % i == 0) {
        if (i > n && i <= 2 * n) ans = max(ans, i - n);
        if ((k + 1) / i > n && (k + 1) / i <= 2 * n)
          ans = max(ans, (k + 1) / i - n);
      }
    }
    printf("%lld\n", ans);
    return 0;
  }
  if (n < 3e7) {
    long long ans = -1;
    for (int i = 0; i <= n; i++) {
      long long res = k % (n + i);
      if (res < d) continue;
      if (res > 2 * d) continue;
      long long u = res - d;
      if (u > i) continue;
      long long uu = i - u;
      if (n - d < uu - 1) continue;
      ans = i;
    }
    printf("%lld\n", ans);
    return 0;
  }
  long long best = -1;
  for (int cyc = 0; cyc < 5000; cyc++) {
    long long l = -1, r = 1e12;
    long long lo = 0, hi = n + 1;
    while (lo != hi) {
      long long mid = (lo + hi) / 2;
      int ok = 1;
      if (k / (n + mid) > cyc) ok = 0;
      long long res = k - (long long)cyc * (n + mid);
      if (res > 2 * d) ok = 0;
      if (res > d + mid) ok = 0;
      if (ok)
        hi = mid;
      else
        lo = mid + 1;
    }
    l = lo;
    lo = -1, hi = n + 1;
    while (lo != hi) {
      long long mid = (lo + hi + 1) / 2;
      int ok = 1;
      if (k / (n + mid) < cyc) ok = 0;
      long long res = k - (long long)cyc * (n + mid);
      if (res < d) ok = 0;
      long long need = max(0ll, mid - (n - d) - 1);
      if (cyc == 0 && mid == 5) ("! %lld %lld\n", need, res);
      if (res < d + need) ok = 0;
      if (ok)
        lo = mid;
      else
        hi = mid - 1;
    }
    r = lo;
    if (l == n + 1 || k < (long long)cyc * n) r = -1;
    ("cyc %d l %lld r %lld\n", cyc, l, r);
    if (l > r) continue;
    best = max(best, r);
    ;
  }
  printf("%lld\n", best);
}
