using System; using static System.Console; using System.Linq; using System.Collections.Generic; class Program { static int NN => int.Parse(ReadLine()); static long[] NList => ReadLine().Split().Select(long.Parse).ToArray(); public static void Main() { Solve(); } static void Test() { var r = new Random(); var count = 0; var max = 2000; while (true) { var h = r.Next(max) + 1; var w = r.Next(max) + 1; var la = r.Next(max) + 1; var lb = r.Next(max) + 1; var ka = r.Next(max); var kb = r.Next(max); // 愚直解 var s1 = All(h, w, la, lb, ka, kb); // 作成解 var s2 = Attack(h, w, la, lb, ka, kb); if (s1 != s2) { WriteLine($"{h} {w} {la} {lb} {ka} {kb}"); WriteLine(s1); WriteLine(s2); return; } ++count; if (count % 10 == 0) WriteLine(count); } } static long All(long h, long w, long la, long lb, long ka, long kb) { var ans = long.MaxValue; for (var ai = 0; Math.Max(ai, ai * ka) <= h * w + ka; ++ai) for (var bi = 0; Math.Max(bi, bi * kb) <= h * w + kb; ++bi) { var hs = Math.Min(h, ai * la); var ws = Math.Min(w, bi * lb); if (hs * ws + ai * ka + bi * kb >= h * w) ans = Math.Min(ans, ai + bi); } return ans; } static void Solve() { var c = NList; var (h, w, la, lb, ka, kb) = (c[0], c[1], c[2], c[3], c[4], c[5]); WriteLine(Attack(h, w, la, lb, ka, kb)); } static long Attack(long h, long w, long la, long lb, long ka, long kb) { var horimax = (h + la - 1) / la; var vertmax = (w + lb - 1) / lb; // var ans = horimax + vertmax; var kmax = Math.Max(ka, kb); if (kmax == 0) { // return ans; return horimax + vertmax; } var ans = long.MaxValue; for (var ai = 0; ai <= h; ++ai) { if (ai == 0 && kb == 0) continue; var ok = h * w; var ng = -1L; while (ok - ng > 1) { var mid = (ok + ng) / 2; var hs = Math.Min(h, ai * la); var ws = Math.Min(w, mid * lb); var cnt = hs * ws + ai * ka + mid * kb; if (cnt >= h * w) ok = mid; else ng = mid; } ans = Math.Min(ans, ai + ok); } for (var bi = 0; bi <= w; ++bi) { if (bi == 0 && ka == 0) continue; var ok = h * w; var ng = -1L; while (ok - ng > 1) { var mid = (ok + ng) / 2; var hs = Math.Min(h, mid * la); var ws = Math.Min(w, bi * lb); var cnt = hs * ws + bi * kb + mid * ka; if (cnt >= h * w) ok = mid; else ng = mid; } ans = Math.Min(ans, bi + ok); } return ans; } }