import java.io.*; import java.util.*; import java.util.stream.*; public class Main { static Coupon[] coupons = new Coupon[3]; static ArrayList> dp = new ArrayList<>(); public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); long n = sc.nextLong(); for (int i = 0; i < 3; i++) { coupons[i] = new Coupon(sc.nextInt(), sc.nextInt()); dp.add(new HashMap<>()); } Arrays.sort(coupons); long lcm = 1; for (Coupon x : coupons) { lcm = getLCM(x.count, lcm); } long max = 0; for (Coupon x : coupons) { max = Math.max(max, lcm / x.count * x.value); } long ans = n / lcm * max; n %= lcm; System.out.println(ans + dfw(2, n)); } static long getLCM(long x, long y) { return x / getGCD(x, y) * y; } static long getGCD(long x, long y) { if (y == 0) { return x; } else { return getGCD(y, x % y); } } static long dfw(int idx, long v) { if (v < 0) { return Long.MIN_VALUE; } if (idx == 0) { return v / coupons[0].count * coupons[0].value; } if (!dp.get(idx).containsKey(v)) { dp.get(idx).put(v, Math.max(dfw(idx - 1, v), dfw(idx, v - coupons[idx].count) + coupons[idx].value)); } return dp.get(idx).get(v); } static class Coupon implements Comparable { int count; int value; public Coupon(int count, int value) { this.count = count; this.value = value; } public int compareTo(Coupon another) { return count - another.count; } } } class Utilities { static String arrayToLineString(Object[] arr) { return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n")); } static String arrayToLineString(int[] arr) { return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new)); } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); StringBuilder sb = new StringBuilder(); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public double nextDouble() throws Exception { return Double.parseDouble(next()); } public int[] nextIntArray() throws Exception { return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray(); } public String next() throws Exception { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }