import java.io.*; import java.util.Scanner; public class Main_yukicoder740 { private static Scanner sc; private static Printer pr; private static void solve() { int n = sc.nextInt(); int m = sc.nextInt(); int p = sc.nextInt(); int q = sc.nextInt(); int rem = n; for (int i = 1; i <= n; i++) { int mo = i % 12; if (mo == 0) { mo = 12; } if (mo >= p && mo <= p + q - 1) { rem -= 2 * m; } else { rem -= m; } // pr.println(rem); if (rem <= 0) { pr.println(i); break; } } } // --------------------------------------------------- public static void main(String[] args) { sc = new Scanner(System.in); pr = new Printer(System.out); solve(); pr.close(); sc.close(); } static class Printer extends PrintWriter { Printer(OutputStream out) { super(out); } } }