#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, k, l, r;
  cin >> n >> l >> r >> k;
  long long len = (r + n - l) % n;
  len++;
  if (n <= 1000000) {
    for (long long i = n; i >= 0; i--) {
      int tmp = k % (n + i);
      if (len == n && tmp == 0) {
        cout << i << endl;
        return 0;
      }
      if (tmp >= len && tmp <= len + min(len, i)) {
        tmp -= len;
        if (tmp < len) tmp++;
        if (n - len + tmp >= i) {
          cout << i << endl;
          return 0;
        }
      }
    }
  } else {
    for (long long i = k / (n << 1); i <= k / n; i++)
      if (i == 0) {
        if (k < len) {
          cout << -1 << endl;
          return 0;
        } else {
          cout << min(len, k - len + 1) + n - len << endl;
          return 0;
        }
      } else {
        if (len == n && k % i == 0) {
          cout << k / i - n << endl;
          return 0;
        }
        long long ans = -1;
        if (k >= 3 * len + n && (k - 2 * len) % i == 0) {
          ans = max(ans, (k - 2 * len) / i - n);
        }
        long long tmp = (k - i * n - 2 * len + 1 + n) / (i + 1);
        tmp = min(tmp, (k - len) / i - n);
        if ((tmp + n) * i >= (k - 2 * len + 1)) ans = max(ans, tmp);
        if (ans != -1) {
          cout << ans << endl;
          return 0;
        }
      }
  }
  cout << "-1" << endl;
  return 0;
}
