#include <bits/stdc++.h>
using namespace std;
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  long long n, l0, r0, k;
  cin >> n >> l0 >> r0 >> k;
  long long x = (r0 - l0 + n) % n + 1;
  if (k < x) {
    cout << -1 << endl;
    return 0;
  }
  if (x == n) {
    long long res = -1;
    for (long long k1 : {k, k + 1}) {
      long long l = k1 == k ? 0 : 1;
      for (long long d = 1; d * d <= k1; ++d)
        if (k1 % d == 0) {
          for (long long t : {d - n, k1 / d - n}) {
            if (t >= l && t <= n) {
              res = max(res, t);
            }
          }
        }
    }
    cout << res << endl;
    return 0;
  }
  const long long N = 2000000;
  if (n <= N) {
    for (int t = n; t >= 0; --t) {
      int rem = k % (n + t) - x;
      if (rem < 0) continue;
      bool ok = 0;
      for (int t1 : {rem, rem + 1}) {
        if (t1 >= 0 && t1 <= min(x, (long long)t) && t - t1 <= n - x) {
          ok = 1;
          break;
        }
      }
      if (ok) {
        cout << t << endl;
        return 0;
      }
    }
    cout << -1 << endl;
  } else {
    long long res = -1;
    for (long long m = 0; m <= k / N; ++m) {
      for (long long D : {k - x, k - x + 1}) {
        long long l = 0, r = n;
        if (m) {
          r = min(r, (k - x) / m - n);
        }
        if (m) {
          l = max(l, (D - x + m - 1) / m - n);
        } else if (D > x) {
          l = r + 1;
        }
        long long D1 = (D - m * n);
        if (D1 >= 0) {
          l = max(l, (D1 + m) / (m + 1));
        } else {
          l = max(l, D1 / (m + 1));
        }
        long long D2 = D - x + n - m * n;
        if (D2 >= 0) {
          r = min(r, D2 / (m + 1));
        } else {
          r = min(r, (D2 - m) / (m + 1));
        }
        if (l <= r) {
          res = max(res, r);
        }
      }
    }
    cout << res << endl;
  }
  return 0;
}
