In one one-dimensional world there are n platforms. Platform with index k (platforms are numbered from 1) is a segment with coordinates [(k - 1)m, (k - 1)m + l], and l < m. Grasshopper Bob starts to jump along the platforms from point 0, with each jump he moves exactly d units right. Find out the coordinate of the point, where Bob will fall down. The grasshopper falls down, if he finds himself not on the platform, but if he finds himself on the edge of the platform, he doesn't fall down.

Input

The first input line contains 4 integer numbers n, d, m, l (1 ≤ n, d, m, l ≤ 106, l < m) — respectively: amount of platforms, length of the grasshopper Bob's jump, and numbers m and l needed to find coordinates of the k-th platform: [(k - 1)m, (k - 1)m + l].

Output

Output the coordinates of the point, where the grosshopper will fall down. Don't forget that if Bob finds himself on the platform edge, he doesn't fall down.

Examples

Input

2 2 5 3


Output

4


Input

5 4 11 8


Output

20
import java.io.*;
import java.math.BigInteger;

import static java.lang.Math.*;
public class Main {
    StreamTokenizer in;
    //BufferedReader in;
    PrintWriter out;
    public static void main(String[] args) throws IOException {
        new Main().run2();
    }
    int ni() throws IOException {
        in.nextToken();
        return (int)in.nval;
    }
    int[] tree;
    int[] left, right;
    int[][] asks;
    boolean[] closed;
    void run4() throws IOException {
        out = new PrintWriter(new OutputStreamWriter(System.out));
        in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
        int n = ni();
        BigInteger ret = BigInteger.ZERO;
        asks = new int[5001][2];
        int[] used = new int[2001];
        closed = new boolean[n];
        int last = 0;
        for(int i = 0; i < n; i++) {
            in.nextToken();
            if(in.sval.charAt(0) == 'w') {
                asks[last][0] = 1;
                asks[last++][1] = ni();
            }
            else {
                asks[last][0] = 2;
                int d = ni();
                used[d] = i;
                asks[last++][1] = d;
            }
        }
        tree = new int[n * 8];
        left = new int[n * 8];
        right = new int[n * 8];
        makeTree(1, 0, n - 1);
        int k;
        while((k = findMax(1, 0, n - 1)) != -1) {
            int r = used[k];
            int i = r - 1;
            while(i >= 0) {
                if(asks[i][0] == 1 && asks[i][1] == k && !closed[i]) break;
                i--;
            }
            if(i == -1) close(1, r, r);
            else {
                ret = ret.add(BigInteger.ONE.shiftLeft(k));
                close(1, i, r);
                for(; i <= r; i++) closed[i] = true;
            }
        }
        out.print(ret);
        out.flush();
    }
    void close(int i, int l, int r) {
        if(l > right[i] || r < left[i]) return;
        if(left[i] == right[i]) {
            tree[i] = -1;
            return;
        }
        close(i << 1, l, r);
        close((i << 1) + 1, l, r);
        tree[i] = max(tree[i << 1], tree[(i << 1) + 1]);
    }
    int findMax(int i, int l, int r) {
        if(l > right[i] || r < left[i]) return -1;
        if(l <= left[i] && r >= right[i])
            return tree[i];
        int a = findMax(i << 1, l, r);
        int b = findMax((i << 1) + 1, l, r);
        return max(a, b);
    }
    void makeTree(int i, int l, int r) {
        if(l > r) {
            tree[i] = -1;
            return;
        }
        left[i] = l;
        right[i] = r;
        if(l == r) {
            if(asks[l][0] == 1) tree[i] = -1;
            else tree[i] = asks[l][1];
            return;
        }
        makeTree(i << 1, l, (l + r) >> 1);
        makeTree((i << 1) + 1, ((l + r) >> 1) + 1, r);
        tree[i] = max(tree[i << 1], tree[(i << 1) + 1]);
    }
    void run3() throws IOException {
        out = new PrintWriter(new OutputStreamWriter(System.out));
        in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
        int n = ni();
        long[] sum = new long[n];
        sum[0] = ni();
        for(int i = 1; i < n; i++)
            sum[i] = sum[i-1] + ni();
        int ret = 0;
        for(int i = 0; i < n - 1; i++)
            if((sum[i] << 1) == sum[n-1]) ret++;
        out.print(ret);
        out.flush();
    }
    void run2() throws IOException {
        out = new PrintWriter(new OutputStreamWriter(System.out));
        in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
        long n = ni(), d = ni(), m = ni(), l = ni();
        long k = 0;
        long x = 0;
        while( k < n ) {
            if(x + d >= m) {
                x += d;
                k += x / m;
                x %= m;
            }
            else {
                x+= ((l - x) / d) * d;
                x += d;
                k += x / m;
                x %= m;
            }
            if(x > l) {
                out.print(m*k + x);
                out.flush();
                return;
            }
        }
        out.print(m*k + x);
        out.flush();
    }
    void run1() throws IOException {
        //in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(new OutputStreamWriter(System.out));
        in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));

        int x1 = ni(), y1 = ni(), x2 = ni(), y2 = ni(), x3 = ni(), y3 = ni();
        if(check(x1, y1, x2, y2, x3, y3)) {
            out.println("RIGHT");
            out.flush();
            return;
        }
        else {
            x1++;
            if(check(x1, y1, x2, y2, x3, y3)) {
                out.println("ALMOST");
                out.flush();
                return;
            }
            x1--;
            y1++;
            if(check(x1, y1, x2, y2, x3, y3)) {
                out.println("ALMOST");
                out.flush();
                return;
            }
            y1--;
            x2++;
            if(check(x1, y1, x2, y2, x3, y3)) {
                out.println("ALMOST");
                out.flush();
                return;
            }
            x2--;
            y2++;
            if(check(x1, y1, x2, y2, x3, y3)) {
                out.println("ALMOST");
                out.flush();
                return;
            }
            y2--;
            x3++;
            if(check(x1, y1, x2, y2, x3, y3)) {
                out.println("ALMOST");
                out.flush();
                return;
            }
            x3--;
            y3++;
            if(check(x1, y1, x2, y2, x3, y3)) {
                out.println("ALMOST");
                out.flush();
                return;
            }
            y3--;
        }
        out.println("NEITHER");
        out.flush();
    }
    boolean check(int x1, int y1, int x2, int y2, int x3, int y3) {
        long a = (x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2);
        double sa = sqrt(a);
        long b = (x3 - x2)*(x3 - x2) + (y3 - y2)*(y3 - y2);
        double sb = sqrt(b);
        long c = (x1 - x3)*(x1 - x3) + (y1 - y3)*(y1 - y3);
        double sc = sqrt(c);
        return (sa - sb - sc < -1e-9 && sb - sa - sc < -1e-9 && sc - sb - sa < -1e-9) && (a == b + c || b == a + c || c == a + b);
    }
}