#include <bits/stdc++.h>
using namespace std;
inline char gc() {
  static char buf[100000], *p1 = buf, *p2 = buf;
  return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)
             ? EOF
             : *p1++;
}
inline long long read() {
  long long x = 0;
  char ch = getchar();
  bool positive = 1;
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') positive = 0;
  for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0';
  return positive ? x : -x;
}
inline void write(long long a) {
  if (a < 0) {
    a = -a;
    putchar('-');
  }
  if (a >= 10) write(a / 10);
  putchar('0' + a % 10);
}
inline void wri(long long a) {
  write(a);
  putchar(' ');
}
inline void writeln(long long a) {
  write(a);
  puts("");
}
const long long inf = 1e18;
;
long long n, l, r, k, t;
pair<long long, long long> jiao(pair<long long, long long> x,
                                pair<long long, long long> y) {
  return make_pair(max(x.first, y.first), min(x.second, y.second));
}
inline long long chu(long long x, long long y) {
  if (y == 0) return -inf;
  return x % y == 0 ? x / y : x / y + 1;
}
void solve(long long l, long long r, int id) {
  long long ans = -1;
  for (long long i = n, pos, jb, L, R; i <= 2 * n; i = pos + 1) {
    jb = k / i;
    pos = jb ? k / jb : inf;
    if (id & 2) {
      L = chu(k - 2 * t, jb);
      if (jb == 0 && k > 2 * t) L = inf;
    } else {
      L = chu(k - t + n, jb + 1);
    }
    if (id & 1) {
      R = (k + 2 * n + 1 - 2 * t) / (jb + 1);
    } else {
      R = jb ? (k - t) / jb : inf;
      if (jb == 0 && k < t) R = -inf;
    }
    pair<long long, long long> T =
        jiao(jiao(make_pair(l + n, r + n), make_pair(L, R)), make_pair(i, pos));
    if (T.first <= T.second) ans = max(ans, T.second);
  }
  if (ans >= 0) {
    cout << ans - n << endl;
    exit(0);
  }
}
signed main() {
  n = read();
  l = read();
  r = read();
  k = read();
  t = (r - l + n) % n + 1;
  if (t == n) {
    long long ans = -1;
    for (long long i = 1; i * i <= k; i++)
      if (k % i == 0) {
        if (i >= n && i <= 2 * n) ans = max(ans, i - n);
        if (k / i >= n && k / i <= 2 * n) ans = max(ans, k / i - n);
      }
    for (long long i = 1; i * i <= k + 1; i++)
      if ((k + 1) % i == 0) {
        if (i > n && i <= 2 * n) ans = max(ans, i - n);
        if ((k + 1) / i > n && (k + 1) / i <= 2 * n)
          ans = max(ans, (k + 1) / i - n);
      }
    cout << ans << endl;
    return 0;
  }
  if (t <= (n - (t - 1))) {
    solve(n - t + 1, n, 3);
    solve(t, n - t + 1, 2);
    solve(0, t, 0);
  } else {
    solve(t, n, 3);
    solve(n - t + 1, t, 1);
    solve(0, n - t + 1, 0);
  }
  puts("-1");
}
