local mmi, mma, mce = math.min, math.max, math.ceil local d, h1, h2, h3 = io.read("*n", "*n", "*n", "*n") local function getcount(d, min, mid, max) local cnt = 0 if max <= mid then local midcnt = mce((mid - max + 1) / d) mid = mid - midcnt * d cnt = cnt + midcnt end if mid <= 0 then return -1 end if mid <= min then local mincnt = mce((min - mid + 1) / d) min = min - mincnt * d cnt = cnt + mincnt end if min <= 0 then return -1 end return cnt end local ret = -1 local a = getcount(d, h1, h3, h2) if 0 <= a then if ret == -1 then ret = a else ret = mmi(ret, a) end end a = getcount(d, h3, h1, h2) if 0 <= a then if ret == -1 then ret = a else ret = mmi(ret, a) end end a = getcount(d, h2, h1, h3) if 0 <= a then if ret == -1 then ret = a else ret = mmi(ret, a) end end a = getcount(d, h2, h3, h1) if 0 <= a then if ret == -1 then ret = a else ret = mmi(ret, a) end end print(ret)