A monster is chasing after Rick and Morty on another planet. They're so frightened that sometimes they scream. More accurately, Rick screams at times *b*, *b* + *a*, *b* + 2*a*, *b* + 3*a*, ... and Morty screams at times *d*, *d* + *c*, *d* + 2*c*, *d* + 3*c*, .... 

The Monster will catch them if at any point they scream at the same time, so it wants to know when it will catch them (the first time they scream at the same time) or that they will never scream at the same time.
The first line of input contains two integers *a* and *b* (1 ≤ *a*, *b* ≤ 100). 

The second line contains two integers *c* and *d* (1 ≤ *c*, *d* ≤ 100).
In the first sample testcase, Rick's 5th scream and Morty's 8th time are at time 82. 

In the second sample testcase, all Rick's screams will be at odd times and Morty's will be at even times, so they will never scream at the same time.
20 2
9 19
82
2 1
16 12
-1
39 52
88 78
1222
59 96
34 48
1748
87 37
91 29
211
11 81
49 7
301
39 21
95 89
3414
59 70
48 54
1014
87 22
98 32
718
15 63
51 13
-1
39 7
97 91
1255
18 18
71 71
1278
46 71
16 49
209
70 11
74 27
2321
94 55
20 96
-1
18 4
77 78
1156
46 44
23 55
-1
74 88
77 37
1346
94 37
34 7
789
22 81
80 88
-1
46 30
34 62
674
40 4
81 40
364
69 48
39 9
48
89 93
84 87
5967
17 45
42 65
317
41 85
95 46
331
69 30
41 16
1410
93 74
99 93
-1
17 19
44 75
427
45 63
98 53
3483
69 11
48 34
-1
55 94
3 96
204
100 100
100 100
100
1 1
1 1
1
1 1
1 100
100
1 100
100 1
101
98 1
99 100
9703
98 1
99 2
9605
97 2
99 100
4852
3 3
3 1
-1
3 2
7 2
2
2 3
2 5
5
2 3
2 3
3
100 3
100 5
-1
6 10
12 14
-1
4 2
4 4
-1
2 3
2 2
-1
2 3
4 99
99
1 5
1 5
5
1 100
3 1
100
2 2
2 1
-1
2 10
6 20
20
2 2
2 10
10
3 7
3 6
-1
1 100
1 100
100
7 25
39 85
319
84 82
38 6
82
7 7
7 14
14
import sys
import math
import bisect

def solve(a, b, c, d):
    A = []
    B = []
    for i in range(200):
        A.append(b + a * i)
    for i in range(200):
        B.append(d + c * i)
    s = set(A) & set(B)
    if len(s) == 0:
        return -1
    return min(s)

def main():
    a, b = map(int, input().split())
    c, d = map(int, input().split())
    ans = solve(a, b, c, d)
    print(ans)

if __name__ == "__main__":
    main()
