#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
template <class C>
void mini(C &a4, C b4) {
  a4 = min(a4, b4);
}
template <class C>
void maxi(C &a4, C b4) {
  a4 = max(a4, b4);
}
template <class TH>
void _dbg(const char *sdbg, TH h) {
  cerr << sdbg << '=' << h << endl;
}
template <class TH, class... TA>
void _dbg(const char *sdbg, TH h, TA... a) {
  while (*sdbg != ',') cerr << *sdbg++;
  cerr << '=' << h << ',';
  _dbg(sdbg + 1, a...);
}
template <class T>
ostream &operator<<(ostream &os, vector<T> V) {
  os << "[";
  for (auto vv : V) os << vv << ",";
  return os << "]";
}
template <class L, class R>
ostream &operator<<(ostream &os, pair<L, R> P) {
  return os << "(" << P.first << "," << P.second << ")";
}
long long n, k, l, r;
long long res = -1;
void spr(long long ob) {
  if (ob <= 0) return;
  long long kk = k - r - n * ob;
  if (kk < 0) return;
  long long res1 = kk / ob;
  long long res2 = kk % ob;
  if (res1 > n) {
    res2 += ob * (res1 - n);
    res1 = n;
  }
  (res2, res1, ob, kk);
  if (res2 < r - 1 - n + res1) {
    long long pom = r - 1 - n + res1 - res2;
    (pom);
    long long il = (pom + ob) / (ob + 1);
    res1 -= il;
    res2 += ob * il;
  }
  (res2, res1);
  assert(res2 >= r - 1 - n + res1);
  if (res2 > r || res1 < res2) {
    return;
  }
  maxi(res, res1);
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(11);
  if (0) cout << fixed << setprecision(6);
  cin >> n >> l >> r >> k;
  r = (r - l + 1 + n) % n;
  if (r == 0) r = n;
  if (k < r) {
    cout << "-1\n";
    return 0;
  }
  if (k <= 2 * r) {
    long long jed = max(0ll, 2 * r - k - 1);
    cout << n - jed << "\n";
    return 0;
  }
  vector<long long> can;
  if (k / n < 1e6) {
    for (long long ob = 0; ob * n <= k; ob++) {
      spr(ob);
    }
  } else {
    for (long long i = (0); i <= ((long long)(n + 1) - 1); i++) {
      long long ob = k / (n + i);
      spr(ob);
      spr(ob + 1);
      spr(ob - 1);
    }
  }
  cout << res << "\n";
}
