#include <fstream>
#define I_F "bs.in"
#define O_F "bs.out"
using namespace std;
long max(long a, long b);
long min(long a, long b);
void Exchange(long &a, long &b);
int main()
{
long co,cx,mo,mx;
long ans;
ifstream fin(I_F);
ofstream fout(O_F);
while (!fin.eof())
{
ans=0;
fin>>co>>cx>>mo>>mx;
if ((mo==0)||(mx==0))
ans=max(min(co,mo),min(cx,mx));
else
{
if (co>cx)
{
Exchange(co,cx);
Exchange(mo,mx);
}
ans=co+min(min(cx/(co+1),mx)*(co+1),cx);
}
fout<<ans<<'\n';
}
fin.close();
fout.close();
return 0;
}
long max(long a, long b)
{
if (a>b)
return a;
else
return b;
}
long min(long a, long b)
{
if (a<b)
return a;
else
return b;
}
void Exchange(long &a, long &b)
{
long t=a;
a=b;
b=t;
}