#include <bits/stdc++.h>
using namespace std;
bool cmp(vector<int> a, vector<int> b) { return a[2] < b[2]; }
template <typename T>
T gcd(T a, T b) {
  return b ? gcd(b, a % b) : a;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int qq = 1;
  while (qq--) {
    long long n, d, m, l;
    cin >> n >> d >> m >> l;
    if (d > m)
      for (long long i = 0;; i += d) {
        if (i % m > l || i > (n - 1) * m + l) {
          cout << i;
          return 0;
        }
      }
    long long now = 0, del, bl = 0;
    vector<int> v;
    v.push_back(0);
    while (1) {
      now += d;
      if (now <= l) bl = now;
      if (now >= m) {
        del = now % m;
        bl = max(bl, now % m);
        break;
      }
      if (now > l && now < m) {
        cout << now;
        return 0;
      }
      v.push_back(now % m);
    }
    now = 0;
    long long del_now = 0;
    while (1) {
      if (now + del_now > (n - 1) * m + l) {
        while (now + del_now > (n - 1) * m + l) {
          now -= d;
        }
        now += d;
        cout << now + del_now;
        return 0;
      }
      long long blt = del_now + ((l - del_now) / d) * d;
      while (blt < m) {
        if (blt > l) {
          cout << now + blt << endl;
          return 0;
        } else
          blt += d;
      }
      now += m;
      del_now += del;
      if (del_now >= m) {
        del_now = del_now % m;
        now += m;
      }
    }
  }
}
