import java.io.*;
import java.util.*;

public class elevator_md_assert implements Runnable {
	private CheckScanner in;
	private PrintWriter out;

	public void run() {
		try {
			solve();
		} catch (IOException e) {
			e.printStackTrace();
			System.exit(1);
		}
	}

	private void solve() throws IOException {
		Locale.setDefault(Locale.US);
		in = new CheckScanner(new File("elevator.in"));
		out = new PrintWriter("elevator.out");
		long h = in.nextLong(1, 1000000000L * 1000000000L);
		in.eoln();
		int a = in.nextInt(1, 100000);
		int b = in.nextInt(1, 100000);
		int c = in.nextInt(1, 100000);
		long[] first = new long[c];
		Arrays.fill(first, h);
		PriorityQueue<Long> queue = new PriorityQueue<Long>();
		queue.add(0L);
		while (!queue.isEmpty()) {
			long v = queue.poll();
			if (v >= h)
				break;
			int rest = (int) (v % c);
			if (first[rest] <= v)
				continue;
			first[rest] = v;
			queue.add(v + a);
			queue.add(v + b);
		}
		long ans = 0;
		long h1 = h - h % c;
		for (int i = 0; i < c; i++) {
			if (first[i] == h)
				continue;
			long last = h1 + i;
			if (last < h)
				last += c;
			ans += (last - first[i]) / c;
		}
		out.println(ans);
		in.close();
		out.close();
	}

	public static void main(String[] args) {
		new Thread(new elevator_md_assert()).start();
	}
}
