#include <bits/stdc++.h>
long long c[1000001];
long long st[1000001], la[1000001];
long long ast[1000001], ala[1000001];
int main() {
  long long i, n, d, m, l, left, right, mid;
  long long dis;
  bool p;
  scanf("%lld%lld%lld%lld", &n, &d, &m, &l);
  for (i = 1; i <= n; i++) {
    st[i] = (i - 1) * m;
    la[i] = st[i] + l;
  }
  for (i = 1; i <= n; i++) {
    left = 0;
    right = (la[n] - 1) / d + 1;
    while (left < right) {
      mid = (left + right) >> 1;
      dis = mid * d;
      if (dis < st[i])
        left = mid + 1;
      else
        right = mid;
    }
    ast[i] = left * d;
    left = 0;
    right = (la[n] - 1) / d + 1;
    while (left < right) {
      mid = (left + right + 1) >> 1;
      dis = mid * d;
      if (dis > la[i])
        right = mid - 1;
      else
        left = mid;
    }
    ala[i] = left * d;
  }
  c[1] = 0;
  for (i = 2; i <= n; i++) {
    if (ala[i - 1] >= ast[i - 1])
      c[i] = i - 1;
    else
      c[i] = c[i - 1];
  }
  p = false;
  for (i = 2; i <= n; i++)
    if (ala[i] >= ast[i] && ast[i] - ala[c[i]] > d) {
      printf("%lld", ala[c[i]] + d);
      p = true;
      break;
    }
  if (!p) printf("%lld", ala[n] + d);
  return 0;
}
