#include <bits/stdc++.h>
using namespace std;
long long n, l, r, k, ans = -1;
inline bool g1(long long i) { return k % i >= max(r, i - 2 * (n - r) - 1); }
inline bool g2(long long i) { return k % i <= min(2 * r, i - n + r); }
int main() {
  cin >> n >> l >> r >> k;
  r = (r - l + 1 + n) % n;
  if (n <= 1e7) {
    for (long long i = 2 * n; i >= n; --i)
      if (g1(i) && g2(i)) return cout << i - n, 0;
  } else {
    if (k <= 2 * r && k >= r) ans = min(r, k - r + 1) + n - r + n;
    for (long long i = max(1ll, k / n / 2); i <= k / n; ++i) {
      long long a = max(n, k / (i + 1) + 1), b = min(2 * n, k / i);
      while (a <= b) {
        long long d = (a + b + 1) / 2;
        if (!g2(d))
          a = d + 1;
        else if (!g1(d))
          b = d - 1;
        else
          ans = max(ans, d), a = d + 1;
      }
    }
  }
  if (!r) r = n;
  if (k <= 2 * r && k >= r) ans = min(r, k - r + 1) + n - r + n;
  for (long long i = max(1ll, k / n / 2); i <= k / n; ++i) {
    long long a = max(n, k / (i + 1) + 1), b = min(2 * n, k / i);
    while (a <= b) {
      long long d = (a + b + 1) / 2;
      if (!g2(d))
        a = d + 1;
      else if (!g1(d))
        b = d - 1;
      else
        ans = max(ans, d), a = d + 1;
    }
  }
  if (~ans) return cout << ans - n, 0;
  cout << -1;
}
