The Monster and the Screaming


Submit solution

Points: 3
Time limit: 2.0s
Memory limit: 10M

Author:
Problem type

A monster is chasing after Ram and Mohan on another planet. They're so frightened that sometimes they scream. More accurately,

Ram screams at times b, b + a, b + 2a, b + 3a, ... and

Mohan screams at times d, d + c, d + 2c, d + 3c, ....

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.

Input

The first line of inputs contains two integers a and b (1 ≤ a, b ≤ 100).

The second line contains two integers c and d (1 ≤ c, d ≤ 100).

Output

Print the first time Ram and Mohan will scream at the same time, or  - 1 if they will never scream at the same time.

Example

input

59 96

34 48

output

1748


Comments

There are no comments at the moment.