N = int(input()) P, Q, R = map(int, input().split()) A, B, C = map(int, input().split()) L = 0 D = 0 for x in range(0, N + 1): if x % P == A and x % Q == B and x % R == C: L = x D = D + 1 break while L <= N: L = L + P * Q * R D = D + 1 print(D)