Problem: Takahashi decided to go sightseeing in New York with Apple. Takahashi didn't have any particular hope for sightseeing, but due to Sachika-chan's enthusiastic invitation, he decided to go sightseeing in the "hosonogai place" as shown in the map below.

<image> Google Maps-(C) 2012 Google

This "horizontal place" is very elongated and can be regarded as a straight line. In addition, there is a start point at one end and a goal point at the other end, and several tourist carriages are running from the start point to the goal point. This carriage operates according to the following rules.

* There are n carriages, and all carriages start from the starting point and proceed to the goal point.
* The size of the carriage can be ignored in all of the following cases:
* Since it is difficult to change the speed on the way, all carriages travel at a constant speed of Si (Si is an integer of 1 or more) per 1 km.
* The carriages have a set departure order, and you must follow this order. However, there is no particular rule regarding the order in which you will arrive at the goal point.
* Multiple carriages cannot depart from the starting point at the same time, and if one carriage departs, there must be at least one minute before the next carriage departs.
* The goal point is wide enough that any number of carriages can arrive at the same time. Also, the carriage that arrives at the goal point stops there and stays at the goal point all the time.
* Since the "Hoso Nagai" is very long and narrow, basically two carriages cannot be lined up in the same place. However, there are special "slightly wide areas" in m, where up to two can be lined up, allowing one carriage to overtake another.



In addition, the following restrictions are satisfied for the above-mentioned "horizontal place" and "slightly wide place".

* There is a straight line from the start point to the goal point, and the distance is (dist) km (dist is an integer greater than or equal to 1).
* There are m "slightly wide areas" somewhere from the start point to the goal point, none of which overlap the start point and goal point. Also, each "slightly wide area" is exactly (Di) km (Di is an integer greater than or equal to 1) from the starting point.



Upon hearing this, Mr. Takahashi adjusted the departure time of the carriage while observing the rules of carriage operation described above, so that the time required from the departure of the first carriage to the arrival of all the carriages was reduced. I found out that I could make it smaller. In order to know the result of Mr. Takahashi, the number of carriages n, the parameter Si regarding the speed of each carriage, the total number of "slightly wide places" existing on the "horizontal place" m, each "slightly wide place" Given the distance Di from the starting point, it's your job to write a program that finds the minimum amount of time it takes for all carriages to arrive after the first carriage departs. In addition, Sachika-chan fully enjoyed sightseeing in "Hosonagai-ko", but Takahashi-kun only muttered "It was hospitable ..." after this sightseeing.

Constraints

> 1 ≤ dist ≤ 100000000 (108)
> 1 ≤ n ≤ 5
> 0 ≤ m ≤ 5
> 1 ≤ Si ≤ 100
> 0 <Di <dist
> If i ≠ j then Di ≠ Dj
> All numbers appearing in the input are integers.
>

* If i <j, the i-th carriage must depart at least 1 minute earlier than the j-th carriage

Input

The input format is as follows.

> dist
> n
> S1
> S2
> ..
> Sn
> m
> D1
> D2
> ..
> Dm
>

* dist represents the distance (km) from the start point to the goal point
* n represents the number of carriages departing from the starting point
* Si represents the speed of the carriage, and the i-th departing carriage represents 1 km in (Si) minutes.
* m represents the total number of "slightly wide areas"
* Di represents the distance (km) from the starting point to each "slightly wide area".

Output

Output the minimum time it takes for all carriages to arrive in one line after the first carriage departs. The unit is minutes.

Examples

Input

100
2
1
2
0


Output

201


Input

100
2
2
1
0


Output

200


Input

100
3
2
1
1
1
50


Output

200


Input

100
4
3
1
1
3
2
40
60


Output

421

Solution (in JAVA):

Solution:
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Scanner;

class Main {
	static double dist;
	static int n;
	static double[] S;
	static int m;
	static double[] D;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		dist = sc.nextDouble();
		n = sc.nextInt();
		S = new double[n];
		for (int i = 0; i < n; ++i) {
			S[i] = sc.nextDouble();
		}
		m = sc.nextInt();
		D = new double[m];
		for (int i = 0; i < m; ++i) {
			D[i] = sc.nextDouble();
		}

		int[] ord1 = new int[n];// ord1[i]:i???????????????????????¬??????ord1[i]
		int[] ord2 = new int[n];// ord2[i]:i??????????????¶??????ord2[i]???????????????????????¬???
		for (int i = 0; i < n; ++i) {
			ord1[i] = i;
		}

		double ans = Double.MAX_VALUE / 10;
		// do {
		for (int i = 0; i < n; ++i) {
			ord2[i] = i;
		}
		do {
			if (ord2[0] != 0)
				continue;
			double[] departTime = new double[n];
			Arrays.fill(departTime, -1);
			departTime[0] = 0;
			ans = Math.min(ans, dfs(ord1, ord2, departTime, 1));
		} while (nextPermutation(ord2));
		// } while (nextPermutation(ord1));
		System.out.println((long) ans);
	}

	// ord1[i]:i???????????????????????¬??????ord1[i]
	// ord2[i]:i??????????????¶??????ord2[i]???????????????????????¬???
	// departTime[i]:i???????????????????????¬????????????

	static double dfs(int[] ord1, int[] ord2, double[] departTime, int cnt) {
		double ans = Double.MAX_VALUE / 10;
		double[] env = new double[m + 1];
		for (int i = 0; i < m; ++i) {
			for (int j = 0; j < n; ++j) {
				if (departTime[j] == -1)
					continue;
				env[i] = Math.max(env[i], S[ord1[j]] * D[i] + departTime[j]);
			}
		}
		for (int i = 0; i < n; ++i) {
			if (departTime[i] == -1)
				continue;
			env[m] = Math.max(env[m], S[ord1[i]] * dist + departTime[i]);
		}
		if (cnt == n) {
			return env[m];
		}
		int curIdx1 = ord2[cnt];
		if (departTime[curIdx1 - 1] != -1) {
			if (check(ord1, ord2, curIdx1, departTime[curIdx1 - 1] + 1, departTime)) {
				departTime[curIdx1] = departTime[curIdx1 - 1] + 1;
				ans = Math.min(ans, dfs(ord1, ord2, departTime, cnt + 1));
				departTime[curIdx1] = -1;
			}
		}

		for (int i = 0; i <= m; ++i) {
			double curDepartTime = env[i] - S[ord1[curIdx1]] * (i == m ? dist : D[i]);
			if (curDepartTime <= 0)
				continue;
			if (check(ord1, ord2, curIdx1, curDepartTime, departTime)) {
				departTime[curIdx1] = curDepartTime;
				ans = Math.min(ans, dfs(ord1, ord2, departTime, cnt + 1));
				departTime[curIdx1] = -1;
			}
		}
		return ans;

	}

	static boolean check(int[] ord1, int[] ord2, int curIdx1, double curDepartTime, double[] departTime) {
		for (int i = 0; i < n; ++i) {
			if (departTime[i] == -1)
				continue;
			if (i < curIdx1 && departTime[i] + 1 > curDepartTime)
				return false;
			if (curIdx1 < i && curDepartTime + 1 > departTime[i])
				return false;
		}
		for (int i = 0; i < n; ++i) {
			if (i == curIdx1 || departTime[i] == -1)
				continue;
			double crossX = -(departTime[i] - curDepartTime) / (S[ord1[i]] - S[ord1[curIdx1]]);
			if (S[ord1[i]] - S[ord1[curIdx1]] == 0)
				continue;
			if (0 < crossX && crossX < dist - 1e-6) {
				boolean f = false;
				for (int j = 0; j < m; ++j) {// X=D??\???????????§??´???cur??¨??´???i???????????£?????????????????????
					if (Math.abs(crossX - D[j]) < 1e-6)
						f = true;
				}
				if (!f)
					return false;
			}
		}
		for (int i = 0; i < m; ++i) {// X=Di??§2?????\??????????????¨????????£?????????????????????
			double curHeight = S[ord1[curIdx1]] * D[i] + curDepartTime;
			int cnt = 0;
			for (int j = 0; j < n; ++j) {
				if (j == curIdx1 || departTime[j] == -1)
					continue;
				double height = S[ord1[j]] * D[i] + departTime[j];
				if (Math.abs(curHeight - height) < 1e-6)
					++cnt;
			}
			if (cnt > 1)
				return false;
		}
		return true;
	}

	static boolean nextPermutation(int[] ord) {
		int len = ord.length;
		int i = len - 1;
		while (i > 0 && ord[i - 1] > ord[i])
			--i;
		if (i == 0)
			return false;
		int j = i;
		while (j + 1 < len && ord[j + 1] > ord[i - 1])
			++j;
		int tmp = ord[i - 1];
		ord[i - 1] = ord[j];
		ord[j] = tmp;
		int s = i;
		int t = len - 1;
		while (t - s > 0) {
			tmp = ord[s];
			ord[s] = ord[t];
			ord[t] = tmp;
			++s;
			--t;
		}
		return true;
	}

	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}