#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
using ii = pair<int, int>;
using ll = long long;
using db = long double;
using PT = pair<ll, ll>;
const int N = 1e6 + 5, K = 105, MOD = 1e9 + 7;
const ll MX = 1e15;
ll n, l, r, k;
void re(ll& l, ll& r) {
  r -= l;
  l = 0;
  if (r < 0) r += n;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> l >> r >> k;
  --l, --r;
  re(l, r);
  r++;
  if (k < r) {
    cout << -1 << '\n';
    return 0;
  }
  if (n <= 400000) {
    ll ans = -1;
    for (ll x = 2 * n; x >= n; --x) {
      ll o = k / x;
      ll rem = k - o * x;
      ll mxSweet = min(r, x - r);
      ll mnSweet = max(0ll, (x - n) - (n - r));
      if (rem == 0) {
        if (r == n) {
          ans = x - n;
          break;
        }
        continue;
      }
      if (rem < r) continue;
      rem -= r;
      if (rem > mxSweet) continue;
      if (rem < mnSweet - 1) continue;
      ans = (x - n);
      break;
    }
    cout << ans << '\n';
  } else {
    ll ans = -1;
    if (k <= r + r) ans = n + k + 1 - r - r;
    if (k == r + r) ans--;
    for (ll o = 1; o * n <= k - r; o++) {
      ll g = min((k - r - n * o) / o, (k - n * o - 2 * r + n + 1) / (o + 1));
      ll tmp = (k - r) % (n + g);
      if (r + g - n - 1 <= tmp && tmp <= g && tmp <= r) ans = max(ans, g);
    }
    cout << ans << '\n';
  }
  return 0;
}
