#!/usr/bin/env python3 d = int(input()) h1 = int(input()) h2 = int(input()) h3 = int(input()) def is_kadomatsu(a, b, c): return a != c and ((a < b and b > c) or (a > b and b < c)) def make_lt(a, b): if b == 0: return float('inf') else: return max(0, (a - (b-1) + d-1) // d) def check_count(k1, k2, k3): if k1 < 0 or k2 < 0 or k3 < 0: return float('inf') g1 = max(0, h1 - k1 * d) g2 = max(0, h2 - k2 * d) g3 = max(0, h3 - k3 * d) if is_kadomatsu(g1, g2, g3): return k1 + k2 + k3 else: return float('inf') if d == 0: if is_kadomatsu(h1, h2, h3): ans = 0 else: ans = -1 else: ans = float('inf') k1 = make_lt(h1, h2) k2 = make_lt(h2, min(h1, h3)) k3 = make_lt(h3, h2) ans = min(ans, check_count(k1, 0, k3 )) ans = min(ans, check_count(k1-1, 0, k3 )) ans = min(ans, check_count(k1 , 0, k3-1)) ans = min(ans, check_count( 0, k2, 0)) ans = min(ans, check_count( 1, k2, 0)) ans = min(ans, check_count( 0, k2, 1)) if ans == float('inf'): ans = -1 print(ans)