#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; int main() { ll d; cin >> d; ll a, b, c; cin >> a >> b >> c; if ((a < b && b > c && a != c) || (a > b && b < c && a != c)) { puts("0"); }else if (b == 0 || d == 0) { puts("-1"); }else { ll ans = 0; ll ta, tb, tc; ta = a; tb = b; tc = c; if (b <= a) { ans += (a-b)/d+1; ta = max(a-((a-b)/d)*d-d, 0LL); } if (b <= c) { ans += (c-b)/d+1; tc = max(c-((c-b)/d)*d-d, 0LL); } if (ta == tc && ta == 0) { puts("-1"); }else { if (ta == tc) ans++; if (min(a, c) == 0) { std::cout << ans << std::endl; }else { std::cout << min(ans, (b-min(a, c))/d+1) << std::endl; } } } }