#include int main(void){ int la,lb,a,b; int x=1; scanf("%d%d%d%d",&la,&lb,&a,&b); while(x%la!=a||x%lb!=b){ x++; } printf("%d",x); }