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.util.Scanner;
import java.util.StringTokenizer;

public class Test {

    public static void main(String[] args) throws IOException {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(in, out);
        out.close();
    }

    private static class TaskB {

        static final double eps = 0.000001;

        public void solve(InputReader in, PrintWriter out) throws IOException {

            long n, d, m, l;
            n = in.nextLong();
            d = in.nextLong();
            m = in.nextLong();
            l = in.nextLong();

            for (int i = 2; i <= n; i++) {
                long k = i - 1;
                long beg = k * m;
                long end = beg - (m - l);
                long fall = (long) Math.ceil((double) end / (double) d) * d;
                if (fall > end && fall < beg) {
                    System.out.println(fall);
                    return;
                }
            }

            long fall = (long) Math.ceil((double) ((n - 1) * m + l) / (double) d) * d;
            if(fall == ((n - 1) * m + l)) fall += d;
            System.out.println(fall);

        }

        static class Point {
            double x, y;

            Point(double x, double y) {
                this.x = x;
                this.y = y;
            }
        }

        static boolean check(double a, double b, double c) {
            if ((a + b > c) && (a + c > b) && (b + c > a)) {
                if (Math.abs(a * a + b * b - c * c) < eps) return true;
                else if (Math.abs(a * a + c * c - b * b) < eps) return true;
                else if (Math.abs(b * b + c * c - a * a) < eps) return true;
                return false;
            }
            return false;
        }

        static long gcd(long a, long b) {
            if (b == 0) return a;
            return gcd(b, a % b);
        }

        static long lcm(long a, long b) {
            return (a * b) / gcd(a, b);
        }

        static double segment(double x1, double y1, double x2, double y2) {
            return Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
        }

    }

    private static class InputReader {
        StringTokenizer st;
        BufferedReader br;

        public InputReader(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        public InputReader(FileReader s) throws FileNotFoundException {
            br = new BufferedReader(s);
        }

        public String next() {
            while (st == null || !st.hasMoreTokens())
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public String nextLine() {
            try {
                return br.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        public boolean ready() {
            try {
                return br.ready();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
    }
}