program xxxx;
var maxx,maxo,counto,countx,zo,zx,w:longint;
begin
assign(input,'bs.in');
reset(input);
assign(output,'bs.out');
rewrite(output);
repeat
begin
readln(counto,countx,maxo,maxx);
if (maxo<>0)and(maxx<>0) then
begin
zo:=counto div maxo;
zx:=countx div maxx;
if counto div maxo<>0 then
inc(zo);
if countx div maxx<>0 then
inc(zx);
if (counto-zx>=-1)and(countx-zo>=-1) then
writeln(counto+countx)
else
begin
if counto-zx<-1 then
w:=counto*maxx+maxx+counto;
if countx-zo<-1 then
w:=countx*maxo+maxo+countx;
writeln(w);
end;
end
else
if maxo=0 then
begin
if maxx<=countx then
writeln(maxx)
else
writeln(countx);
end
else
if maxo<=counto then
writeln(maxo)
else
writeln(counto);
end
until
eof(input);
close(input);
close(output);
end.