import java.util.*;
import java.awt.Checkbox;
import java.io.*;

public class C {
	static ArrayList<Integer> primes;
	static int[] isComposite;
	static int[] idx;
	static int[] p;

	static void sieve(int N) // O(N log log N)
	{
		isComposite = new int[N + 1];
		idx = new int[N + 1];
		isComposite[0] = isComposite[1] = 1; // 0 indicates a prime number
		primes = new ArrayList<Integer>();

		int ix = 1;
		for (int i = 2; i <= N; ++i) // can loop till i*i <= N if primes array is not needed O(N log log sqrt(N))
			if (isComposite[i] == 0) // can loop in 2 and odd integers for slightly better performance
			{
				primes.add(i);
				idx[i] = ix;
				ix++;
				if (1l * i * i <= N)
					for (int j = i * i; j <= N; j += i) // j = i * 2 will not affect performance too much, may alter in
														// modified sieve
						isComposite[j] = 1;
			}
		p = new int[primes.size()];
		int i = 0;
		for (int x : primes) {
			p[i++] = x;
		}
	}

	static long pow(long a, long e) // O(log e)
	{
		long res = 1;
		while (e > 0) {
			if ((e & 1) == 1)
				res *= a;
			a *= a;
			e >>= 1;
		}
		return res;
	}

	static ArrayList<Long> arr = new ArrayList<Long>();

	static void com(int idx, long r) {
		if (idx == 10) {
			arr.add(r);
			return;
		}
		com(idx + 1, r + a[idx]);
		com(idx + 1, r);

	}

	static int bin(long n, ArrayList<Long> b) {
		int s = 0;
		int e = b.size() - 1;
		int ans = -1;

		while (e >= s) {
			int mid = (s + e) / 2;
			long x = b.get(mid);
			if (x <= n) {
				ans = mid;
				s = mid + 1;
			} else
				e = mid - 1;
		}
		return ans;
	}

	static Integer[] a;

	static int bin(int num) {
		int s = 0;
		int e = a.length - 1;
		int ans = -1;
		while (s <= e) {
			int mid = (s + e) / 2;
			if (a[mid] <= num) {
				s = mid + 1;
				ans = mid;
			} else
				e = mid - 1;
		}
		return ans;
	}

	static int bin2(int num) {
		int s = 0;
		int e = a.length - 1;
		int ans = -1;
		while (s <= e) {
			int mid = (s + e) / 2;
			if (a[mid] > num) {
				e = mid - 1;

				ans = mid;
			} else
				s = mid + 1;
		}
		return ans;
	}

	static int[] cum;
	static int n;
	static int m;
	static int x;
	static int y;
	static int[][][] memo;

	static int dp(int idx, int l, int s) {
		if (idx == m)
			return 0;
		if (memo[s][idx][l] != -1)
			return memo[s][idx][l];
		int t = 1000000000;
		int le = 1000000000;
		if (s == 0) {
			if (l != y)
				t = cum[idx + 1] - cum[idx] + dp(idx + 1, l + 1, s);
			if (idx + x <= m)
				le = x * n - (cum[idx + x] - cum[idx]) + dp(idx + x, x, 1);
		} else {
			if (l != y)
				t = n - cum[idx + 1] + cum[idx] + dp(idx + 1, l + 1, s);
			if (idx + x <= m)
				le = cum[idx + x] - cum[idx] + dp(idx + x, x, 0);
		}
		return memo[s][idx][l] = Math.min(t, le);
	}

	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter pw = new PrintWriter(System.out);
		StringTokenizer st = new StringTokenizer(br.readLine());
		n = Integer.parseInt(st.nextToken());
		m = Integer.parseInt(st.nextToken());
		x = Integer.parseInt(st.nextToken());
		y = Integer.parseInt(st.nextToken());
		long ans = m / (y - 1) * y;
		if (m % (y - 1) == 0)
			ans--;
		else
			ans += m % (y - 1);
		long x = n - ans / y;
		if (x <= 0)
			pw.println(ans);
		else {
			long z = x + ans - ans / x;
			ans = z / (x - 1) * x;
			if (z % (x - 1) == 0)
				ans--;
			else
				ans += z % (x - 1);

			pw.println(ans);
		}

		pw.flush();

	}

	static int power(int x, int y) {
		int res = 1; // Initialize result
		x = x; // Update x if it is more
				// than or equal to p
		while (y > 0) {
			// If y is odd, multiply
			// x with result
			if ((y & 1) > 0)
				res = (res * x);

			// y must be even now
			y = y >> 1; // y = y/2
			x = (x * x);
		}
		return res;
	}

	static int sum(long n) {
		int c = 0;
		while (n != 0) {
			c += n % 10;
			n /= 10;
		}
		return c;
	}

	static int g_div(int x) {
		for (int i = 2; i * i <= x; i++)
			if (x % i == 0)
				return x / i;
		return 1;
	}

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

	static class pair implements Comparable<pair> {
		int x;
		int y;
		int z;
		int idx;

		public pair(int d, int u, int w, int in) {
			x = d;
			y = u;
			z = w;
			idx = in;
		}

		@Override
		public int compareTo(pair o) {
			// TODO Auto-generated method stub

			return z - o.z;
		}

	}

	static class pair2 implements Comparable<pair2> {
		int x;
		int y;
		int idx;

		public pair2(int d, int u, int in) {
			x = d;
			y = u;
			idx = in;
		}

		@Override
		public int compareTo(pair2 o) {
			// TODO Auto-generated method stub
			return y - o.y;

		}

	}

	static class pair1 implements Comparable<pair1> {
		int x;
		int idx;

		public pair1(int d, int w) {
			x = d;
			idx = w;
		}

		@Override
		public int compareTo(pair1 o) {
			// TODO Auto-generated method stub

			return x - o.x;
		}

	}

}
