#include <bits/stdc++.h>
using namespace std;
const int INF = INT_MAX / 2, NINF = INT_MIN / 2;
const long double PI = acos(-1.0);
void prepareIO() {
  if (strlen("") != 0) {
    freopen(
        ""
        ".in",
        "r", stdin);
    freopen(
        ""
        ".out",
        "w", stdout);
  }
}
void debout() {}
template <typename Head, typename... Tail>
void debout(Head H, Tail... T) {}
void stressout() {}
template <typename Head, typename... Tail>
void stressout(Head H, Tail... T) {}
class Timer {
 public:
  double begin;
  Timer() : begin(clock()) {}
  ~Timer() {
    fprintf(stderr, "%.6lf\n", (clock() - begin + .0) / CLOCKS_PER_SEC);
  }
} timer_;
void solve1();
int main() {
  prepareIO();
  solve1();
  return 0;
}
void solve1() {
  long long n, d, m, l;
  cin >> n >> d >> m >> l;
  long long start = 0;
  long long cnt = 0;
  while (cnt < n) {
    cnt++;
    start += ((l - start % m) / d + 1) * d;
    if (l - start % m < 0) {
      break;
    }
  }
  cout << start << "\n";
}
