using System;
using System.Collections.Generic;
class Program
{
static string InputPattern = "Input1";
static List<string> GetInputList()
{
var WillReturn = new List<string>();
if (InputPattern == "Input1") {
WillReturn.Add("1");
WillReturn.Add("3");
WillReturn.Add("3");
WillReturn.Add("4");
//1
//真ん中の竹に1度魔法を唱えることで。条件を満たすことができます
}
else if (InputPattern == "Input2") {
WillReturn.Add("411");
WillReturn.Add("4");
WillReturn.Add("1");
WillReturn.Add("5");
//0
//魔法を使う必要がないこともあります
}
else if (InputPattern == "Input3") {
WillReturn.Add("2");
WillReturn.Add("3");
WillReturn.Add("10");
WillReturn.Add("12");
//2
}
else if (InputPattern == "Input4") {
WillReturn.Add("1");
WillReturn.Add("0");
WillReturn.Add("0");
WillReturn.Add("0");
//-1
//魔法を使ってもどうしようもないこともあります
}
else {
string wkStr;
while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
}
return WillReturn;
}
static int D;
static void Main()
{
List<string> InputList = GetInputList();
D = int.Parse(InputList[0]);
int H1 = int.Parse(InputList[1]);
int H2 = int.Parse(InputList[2]);
int H3 = int.Parse(InputList[3]);
Console.WriteLine(DeriveAnswer(H1, H2, H3));
}
static int DeriveAnswer(int pH1, int pH2, int pH3)
{
int wkInt1 = DeriveMahouCnt1(pH1, pH2, pH3);
int wkInt2 = DeriveMahouCnt2(pH1, pH2, pH3);
if (wkInt1 == -1 && wkInt2 == -1) return -1;
if (wkInt1 == -1 && wkInt2 != -1) return wkInt2;
if (wkInt1 != -1 && wkInt2 == -1) return wkInt1;
return Math.Min(wkInt1, wkInt2);
}
//3本の竹全ての高さが互いに異なり、
//真ん中の竹の高さが一番高い状態にする
static int DeriveMahouCnt1(int pH1, int pH2, int pH3)
{
int MahouCnt = 0;
if (D > 0) {
if (pH2 <= pH1) {
int wkCnt = (pH1 - pH2) / D + 1;
ExecMahou(ref pH1, wkCnt);
MahouCnt += wkCnt;
}
if (pH2 <= pH3) {
int wkCnt = (pH3 - pH2) / D + 1;
ExecMahou(ref pH3, wkCnt);
MahouCnt += wkCnt;
}
if (pH1 == pH3) {
ExecMahou(ref pH1, 1);
MahouCnt++;
}
}
if (pH1 == pH2) return -1;
if (pH1 == pH3) return -1;
if (pH2 == pH3) return -1;
if (pH2 <= pH1) return -1;
if (pH2 <= pH3) return -1;
return MahouCnt;
}
//3本の竹全ての高さが互いに異なり、
//真ん中の竹の高さが一番低い状態にする
static int DeriveMahouCnt2(int pH1, int pH2, int pH3)
{
int MahouCnt = 0;
if (D > 0) {
if (pH1 == pH3) {
ExecMahou(ref pH1, 1);
MahouCnt++;
}
if (pH1 <= pH2) {
int wkCnt = (pH2 - pH1) / D + 1;
ExecMahou(ref pH2, wkCnt);
MahouCnt += wkCnt;
}
if (pH3 <= pH2) {
int wkCnt = (pH2 - pH3) / D + 1;
ExecMahou(ref pH2, wkCnt);
MahouCnt += wkCnt;
}
}
if (pH1 == pH2) return -1;
if (pH1 == pH3) return -1;
if (pH2 == pH3) return -1;
if (pH1 <= pH2) return -1;
if (pH3 <= pH2) return -1;
return MahouCnt;
}
//魔法をN回実行する
static void ExecMahou(ref int pTarget, int pN)
{
pTarget = Math.Max(0, pTarget - pN * D);
}
}