#include <bits/stdc++.h>
using namespace std;
const int buben = 3 * 316228;
long long solve(long long c, long long n, long long alpha, long long cnt) {
  long long val = n - cnt + alpha - c * n;
  if (val < 0) {
    return -1;
  }
  long long rg = val / (c + 1);
  rg = min(rg, n);
  if (c == 0) {
    if (alpha < 0) {
      return -1;
    }
  } else {
    val = alpha - c * n;
    if (val < 0) {
      return -1;
    }
    rg = min(rg, val / c);
  }
  long long lf = 0;
  if (c == 0) {
    if (alpha - cnt > 0) {
      return -1;
    }
  } else {
    val = alpha - cnt - c * n;
    if (val >= 0) {
      lf = (val + c - 1) / c;
    }
  }
  val = alpha - c * n;
  if (val >= 0) {
    lf = max(lf, (val + c) / (c + 1));
  }
  if (lf > rg) {
    return -1;
  }
  return rg;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n, l, r, k;
  cin >> n >> l >> r >> k;
  if (n == 1) {
    cout << "1\n";
    return 0;
  }
  long long ans = -1;
  vector<long long> vct = {0};
  for (int i = 1; i <= buben && i <= k; ++i) {
    vct.push_back(i);
    vct.push_back(k / i);
    if (k / i - 1 >= 0) {
      vct.push_back(k / i - 1);
    }
  }
  long long cnt;
  if (r >= l) {
    cnt = r - l + 1;
  } else {
    cnt = r + n - l + 1;
  }
  for (long long c : vct) {
    if (k < cnt || c > k / n) {
      continue;
    }
    ans = max(ans, solve(c, n, k - cnt, cnt));
  }
  for (long long c : vct) {
    if (k < cnt + 2 * c || c > k / n) {
      continue;
    }
    long long s = solve(c, n - 1, k - cnt - 2 * c, cnt - 1);
    if (s != -1) {
      ans = max(ans, s + 1);
    }
  }
  cout << ans << "\n";
}
