import sequtils, strutils let xs = stdin.readLine.split.map parseInt a = xs[0] b = xs[1] x = xs[2] y = xs[3] for i in 0..10000000: if (i mod a) == x: if (i mod b) == y: echo i quit()