Works
At a certain factory, a decision was made to modernize production by purchasing robots. Since processing a part involves two operations, two types of robots were acquired: type A robots handle the first operation, and type B robots handle the second. To cut costs, the factory opted for used robots instead of the latest models. Consequently, the time each robot takes to perform the same operation varies significantly, complicating work scheduling.
Write a program that, given a set of robots of both types, calculates the minimum time required to process a specified number of parts.
Input
The first line contains a natural number N, 1 ≤ N ≤ 100000, representing the number of parts that need processing.
The second line contains a natural number Na, 1 ≤ Na ≤ 1000, indicating the number of robots available for the first operation.
The third line lists Na natural numbers A_i, 1 ≤ A_i ≤ 100, each representing the time the i-th type A robot takes to complete the operation.
The fourth line contains a natural number Nb, 1 ≤ Nb ≤ 1000, indicating the number of robots available for the second operation.
The fifth line lists Nb natural numbers B_i, 1 ≤ B_i ≤ 100, each representing the time the i-th type B robot takes to complete the operation.
Output
Output a single integer on one line, representing the minimum time required for all N parts to be processed first by a type A robot and then by a type B robot. The time to transfer a part from a type A robot to a type B robot is negligible.