N = int(input()) P, Q, R = map(int, input().split()) A, B, C = map(int, input().split()) N1 = pow(Q*R, -1, P)%P N2 = pow(R*P, -1, Q)%Q N3 = pow(P*Q, -1, R)%R x = (A*Q*R*N1 + B*R*P*N2 + C*P*Q*N3)%(P*Q*R) print((N-x)//(P*Q*R)+1 if x <= N else 0)