from collections import defaultdict, deque, Counter # from functools import cache # import copy from itertools import combinations, permutations, product, accumulate, groupby, chain # from more_itertools import distinct_permutations from heapq import heapify, heappop, heappush, heappushpop import math import bisect # from pprint import pprint from random import randint, shuffle, randrange # from sortedcontainers import SortedSet, SortedList, SortedDict import sys sys.setrecursionlimit(5000) input = lambda: sys.stdin.readline().rstrip('\n') inf = float('inf') mod1 = 10**9+7 mod2 = 998244353 def ceil_div(x, y): return -(-x//y) ################################################# xy = [None, None] # ax+by = gcd(a, b) def extend_gcd(a, b, r=0): if b == 0: xy[r] = 1 xy[r^1] = 0 return a d = extend_gcd(b, a%b, r^1) xy[r^1] -= a//b*xy[r] return d def crt(MR): # (x ≡ r mod m) nm = 1 x = 0 for m, r in MR: extend_gcd(nm, m) x += (r-x)*xy[0]%m*nm nm *= m return x N = int(input()) P, Q, R = map(int, input().split()) A, B, C = map(int, input().split()) x = crt([(P, A), (Q, B), (R, C)]) m = math.lcm(P, Q, R) print(N//m + (N%m >= x))