import math A, B, C, D, E = map(int, input().split()) ab = A+B cd = C+D G = math.gcd(ab, cd) L = ab*cd//G ans = 0 for i in range(L): if 0<=i%ab