#include using namespace std; typedef long long ll; typedef vector< int > vi; typedef vector< vi > vvi; typedef vector< ll > vl; typedef vector< vl > vvl; typedef pair< int, int > pii; typedef vector< pii > vp; typedef vector< double > vd; typedef vector< vd > vvd; typedef vector< string > vs; template< class T1, class T2 > int upmin( T1 &x, T2 v ){ if( x > v ){ x = v; return 1; } return 0; } template< class T1, class T2 > int upmax( T1 &x, T2 v ){ if( x < v ){ x = v; return 1; } return 0; } const int INF = 0x3f3f3f3f; int D; vi H; void init(){ cin >> D; H = vi( 3 ); for( int i = 0; i < 3; ++i ) cin >> H[ i ]; } int kado( int a, int b, int c ){ if( a == b or b == c or c == a ) return 0; return b == min( { a, b, c } ) or b == max( { a, b, c } ); } void preprocess(){ if( kado( H[ 0 ], H[ 1 ], H[ 2 ] ) ) cout << 0 << endl, exit( 0 ); } void solve(){ int ans = INF; if( true ){ int f = 0; int zzz = H[ 0 ]; if( H[ 0 ] == H[ 2 ] ){ if( max( 0, H[ 0 ] - D ) == H[ 2 ] ) f = INF; else ++f, H[ 0 ] = max( 0, H[ 0 ] - D ); } int minv = min( H[ 0 ], H[ 2 ] ); if( H[ 1 ] - ( ( H[ 1 ] - minv ) / D * D + D ) >= 0 ) upmin( ans, f + ( H[ 1 ] - minv ) / D + 1 ); H[ 0 ] = zzz; if( H[ 1 ] > 0 ){ int t = 0; if( H[ 2 ] >= H[ 1 ] ) t += ( H[ 2 ] - H[ 1 ] ) / D + 1; if( H[ 0 ] >= H[ 1 ] ) t += ( H[ 0 ] - H[ 1 ] ) / D + 1; int x = H[ 2 ] >= H[ 1 ] ? max( 0, H[ 2 ] - ( ( H[ 2 ] - H[ 1 ] ) / D * D + D ) ) : H[ 2 ]; int y = H[ 0 ] >= H[ 1 ] ? max( 0, H[ 0 ] - ( ( H[ 0 ] - H[ 1 ] ) / D * D + D ) ) : H[ 0 ]; if( x == y ){ if( max( 0, x - D ) == y ) t = INF; else ++t; } upmin( ans, t ); } if( ans == INF ) ans = -1; cout << ans << endl; } } signed main(){ ios::sync_with_stdio( 0 ); init(); preprocess(); solve(); return 0; }