import java.util.*; import java.io.*; class Main{ private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); private static final PrintWriter out = new PrintWriter(System.out); public static void main(String[] args)throws IOException{ String[] str = br.readLine().split(" "); int A = Integer.parseInt(str[0]); int B = Integer.parseInt(str[1]); int a = Integer.parseInt(str[2]); int b = Integer.parseInt(str[3]); for(int i=0;;i++) if(i%A==a&&i%B==b){ out.println(i); break; } br.close(); out.close(); } }