#include <bits/stdc++.h>
using namespace std;
long long n, l, r, k;
inline bool check(long long x) {
  if (x > n || x < 0) return false;
  long long x1min, x1max, ost;
  ost = k % (n + x);
  x1min = x - min(n - r, x) - 1;
  x1max = min(r, x);
  if (x1min <= ost && ost <= x1max) {
    cout << x << endl;
    return true;
  }
  return false;
}
int main() {
  cin >> n >> l >> r >> k;
  r = (r + n - l) % n + 1;
  k -= r;
  if (k < 0) {
    cout << -1 << endl;
    return 0;
  }
  if (check(n - r + k + 1)) return 0;
  if (check(n - r + k)) return 0;
  if (n < 1e7) {
    for (long long y = n; y >= 0; --y)
      if (check(y)) return 0;
    cout << -1 << endl;
    return 0;
  }
  for (long long z = 1, k1 = k; k1 >= n; ++z) {
    k1 -= n;
    long long y2 = min(n - r, k1 / z);
    long long y1 = min(r, (k1 + 1 - z * y2) / (z + 1));
    if (check(y1 + y2)) return 0;
  }
  cout << -1 << endl;
  return 0;
}
