using System; using static System.Console; using System.Linq; using System.Collections.Generic; class Program { static int NN => int.Parse(ReadLine()); static int[] NList => ReadLine().Split().Select(int.Parse).ToArray(); static void Main() { Solve(); } static void Solve() { var t = NN; var c = NList; var (x, a) = (c[0], c[1]); c = NList; var (y, b) = (c[0], c[1]); WriteLine(Time(t, x, a, y, b)); } static long Time(int t, long x, long a, long y, long b) { var res = t < 0 ? long.MaxValue : t; for (var i = 0; a * i < Math.Max(0, t) + a * b / GCD(a, b); ++i) { var j = 0L; if (a * i > t) j = (a * i - t + b - 1) / b; res = Math.Min(res, x * i + y * j + t - (a * i - b * j)); } return res; } static long GCD(long a, long b) { if (a < b) return GCD(b, a); if (a % b == 0) return b; return GCD(b, a % b); } }