#include <bits/stdc++.h>
using namespace std;
const int MOD(1000000007);
const int INF((1 << 30) - 1);
const int MAXN();
int main() {
  long long n, d, m, l;
  cin >> n >> d >> m >> l;
  if (d % m > l) {
    cout << d;
    return 0;
  }
  long long now = 0, pos = 0;
  while (pos % m <= l && now < n) {
    long long t = (l - pos) / d;
    pos += (t + 1) * d;
    now += (pos / m);
    pos %= m;
  }
  cout << now * m + pos;
}
