#include <bits/stdc++.h>
long long A, B, n, d, m, l;
int main() {
  for (std::cin >> n >> d >> m >> l; B < n && A <= l;
       B += (A + d) / m, (A += d) %= m)
    if (d < m) A += (l - A) / d * d;
  std::cout << B * m + A;
}
