#include using namespace std; using ll = long long; int main(){ ll d; vector a(3); cin >> d >> a[0] >> a[1] >> a[2]; auto f0 = [&](ll v1, ll v2, ll v3){ if(v1 == v3)return false; if(v2 > max(v1, v3))return true; return (v2 < min(v1, v3)); }; auto f1 = [&](ll v1, ll v2, ll v3){ ll mn = min(v1, v3); if(mn == 0 || d == 0)return 1ll << 60; ll c = max(0ll, v2 - (mn - 1)), ans = (c + d - 1) / d; if(v1 == v3){ if(v1 <= d)return 1ll << 60; ans++; } return ans; }; auto f2 = [&](ll v1, ll v2, ll v3){ ll ans = 0; if(d == 0)return 1ll << 60; ll c = (max(0ll, v1 - (v2 - 1)) + d - 1) / d; ans += c, v1 -= d * c; c = (max(0ll, v3 - (v2 - 1)) + d - 1) / d; ans += c, v3 -= d * c; if(min(v1, v3) < 0)return 1ll << 60; if(v1 == v3){ if(v1 == 0)return 1ll << 60; } return ans; }; ll ans = min(f1(a[0], a[1], a[2]), f2(a[0], a[1], a[2])); if(f0(a[0], a[1], a[2]))ans = 0; if(ans >> 60)ans = -1; cout << ans << '\n'; }