import sys INF = 10 ** 18 d, h1, h2, h3 = [input() for _ in xrange(4)] def is_kadomatsu(a, b, c): return a != c and (a < b and b > c or a > b and b < c) if is_kadomatsu(h1, h2, h3): print 0 sys.exit() if d == 0: print -1 sys.exit() f = lambda x: max(0, x - d) ans = 0 if h1 == h3: h1 = f(h1) ans += 1 if h1 == h3: print -1 sys.exit() # h1 < h3 and h3 > h2 ans1 = ans t1, t2, t3 = h1, h2, h3 k1 = max(0, (t1 - t2 + d) / d) k3 = max(0, (t3 - t2 + d) / d) t1 = max(0, t1 - k1 * d) t3 = max(0, t3 - k3 * d) ans1 = ans + k1 + k3 if t1 == t3: t1 = f(t1) ans1 += 1 if not is_kadomatsu(t1, t2, t3): ans1 = INF # h1 > h3 and h3 < h2 t1, t2, t3 = h1, h2, h3 k2 = max(0, (t2 - min(t1, t3) + d) / d) ans2 = ans + k2 t2 = max(0, t2 - k2 * d) if not is_kadomatsu(t1, t2, t3): ans2 = INF ans = min(ans1, ans2) if ans == INF: ans = -1 print ans