#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ll n, l, r, k;
  cin >> n >> l >> r >> k;
  ll d = (r >= l) ? r - l + 1 : r + n - l + 1;
  if (n < sqrt(k)) {
    ll ans = -1;
    for (ll i = 0; i <= n; i += 1) {
      ll c = n + i;
      ll more = k % c;
      if (more == 0) {
        if (d == n) ans = i;
      } else {
        if (more >= d && more <= d + min(i, d)) {
          if (i - min(i, min(d, more - d + 1)) <= n - d) ans = i;
        }
      }
    }
    cout << ans << endl;
  } else {
    ll ans = -1;
    if (k >= d && k <= d + d) ans = n - d + min(d, k - d + 1);
    ll c = 1;
    while (ans == -1) {
      ll b = k - n * c - d;
      if (b < 0) break;
      ll x = (b + 1) / c;
      x = min(x, n);
      x = min(x, (n - d + b + 1) / (c + 1));
      ll y = b - x * c;
      if (y >= 0 && y <= d && (x - min(x, min(d, y + 1))) <= n - d)
        ans = x;
      else {
        x = b / c;
        x = min(x, n);
        x = min(x, (n - d + b + 1) / (c + 1));
        y = b - x * c;
        if (y >= 0 && y <= d && (x - min(x, min(d, y + 1))) <= n - d)
          ans = x;
        else
          c += 1;
      }
    }
    cout << ans << endl;
  }
}
