from heapq import heappush, heappop from collections import Counter N = int(input()) P, Q, R = map(int, input().split()) A, B, C = map(int, input().split()) def calc(): freq = Counter() q = [] heappush(q, (A, P)) heappush(q, (B, Q)) heappush(q, (C, R)) res = [] while q: m, x = heappop(q) freq[m] += 1 if freq[m] == 3: res.append(m) if len(res) == 2: d = res[1] - res[0] cnt = (N-res[0]) // d # print(f'{cnt=} {d=}') return cnt+1 heappush(q, (m+x, x)) return 0 ans = calc() print(ans)