Robots#161

Robots

1 second
64 megabytes
Easy

At a certain factory, it was decided to modernize production by purchasing robots. Since each part requires two operations, two types of robots were used: type robots perform the first operation, and type robots perform the second. To save money, the factory bought used robots instead of new ones. As a result, the time each robot takes to perform its operation varies, making scheduling more difficult.

Write a program that, given the available robots of both types, determines the minimum time required to process a given number of parts.

Input

The first line contains a natural number , 1 \leq N \leq 100000, the number of parts to be processed.

The second line contains a natural number N_a, 1 \leq N_a \leq 1000, the number of robots available for the first operation.

The third line contains N_a natural numbers A_i, 1 \leq A_i \leq 100, where A_i is the time the -th type robot takes to complete its operation.

The fourth line contains a natural number N_b, 1 \leq N_b \leq 1000, the number of robots available for the second operation.

The fifth line contains N_b natural numbers B_i, 1 \leq B_i \leq 100, where B_i is the time the -th type robot takes to complete its operation.

Output

Output a single integer: the minimum time required for all parts to be processed first by type robots and then by type robots. Ignore the time to transfer a part from a type robot to a type robot.

Examples

Example 1

Loading
Loading