from itertools import count def solve(): d = int(input()) h1 = int(input()) h2 = int(input()) h3 = int(input()) ans = 0 states = set() states.add((h1, h2, h3)) while states: new = set() for h in states: zs = h.count(0) if zs >= 2: print(-1) return ma = max(h) mi = min(h) if h[0] != h[1] and h[0] != h[2] and h[1] != h[2] and (h[1] == ma or h[1] == mi): print(ans) return if h[1] > 0 and h[1] != ma: new.add((h[0], h[1] - d, h[2])) if h[0] > 0: new.add((h[0] - d, h[1], h[2])) if h[2] > 0: new.add((h[0], h[1], h[2] - d)) states = new ans += 1 print(-1) if __name__ == '__main__': solve()