#include <bits/stdc++.h>
using namespace std;
long long n, m, l, d;
int nextp[1001000];
void Init() {
  for (int i = m; i >= 0; i--) {
    if (i + d <= l) nextp[i] = nextp[i + d];
    if (i + d > l) nextp[i] = i;
  }
}
int main() {
  cin >> n >> d >> m >> l;
  long long st = 0, cnt = 0;
  Init();
  while (true) {
    st += d;
    if (st % m > l || st / m >= n) break;
    cnt = st % m;
    st = st / m * m;
    cnt = nextp[cnt];
    st += cnt;
  }
  cout << st << endl;
  return 0;
}
