#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define sz size() #define pb push_back #define mp make_pair #define fi first #define se second #define all(c) (c).begin(), (c).end() #define rep(i,a,b) for(int i=(a);i<(b);++i) #define clr(a, b) memset((a), (b) ,sizeof(a)) #define MOD 1000000007 int check(int a, int b, int c){ if(a==b||a==c||b==c)return 0; vector v; v.pb(a);v.pb(b);v.pb(c); sort(all(v)); if(b==v[1])return 0; return 1; } int main(){ int d; cin>>d; int h1,h2,h3; cin>>h1>>h2>>h3; int ans = 2000000000; if(check(h1,h2,h3)){ cout << ans << endl; return 0; } else if(d==0){ cout << -1 << endl; return 0; } rep(i,0,3){ rep(j,0,3){ rep(k,0,3){ int a = max(0,h1-d*i); int b = max(0,h2-d*j); int c = max(0,h3-d*k); if(check(a,b,c)){ ans = min(ans,i+j+k); } } } } int mn = min(h1,h3); if(mn==0||((h1<2)&&(h3<2))){ cout << -1 << endl; } cout << min(ans, (h2-mn)/d+1) << endl; return 0; }