题目链接:https://codeforces.com/contest/18/problem/B
#include <iostream>
using namespace std;
int main()
{
int n,d,m,l;
scanf("%d%d%d%d",&n,&d,&m,&l);
long long a,b;
for(int i=1;i<=n;i++)
{
a=1ll*(i-1)*m+l,b=1ll*i*m-1;
if(a/d!=b/d) break;
}
printf("%lld\n",a-a%d+d);
return 0;
}