World Trip

아직 제출이 없습니다시간 제한5초메모리 제한512 MB

문제

Kita_masa is planning a trip around the world. This world has NN countries and the country ii has M_iM\_i cities. Kita_masa wants to visit every city exactly once, and return back to the starting city.

In this world, people can travel only by airplane. There are two kinds of airlines: domestic and international lines. Since international airports require special facilities such as customs and passport control, only a few cities in each country have international airports.

You are given a list of all flight routes in this world and prices for each route. Now it's time to calculate the cheapest route for Kita_masa's world trip!

입력

The first line contains two integers NN and KK, which represent the number of countries and the number of flight routes, respectively. The second line contains NN integers, and the ii-th integer M_iM\_i represents the number of cities in the country ii. The third line contains NN integers too, and the ii-th integer F_iF\_i represents the number of international airports in the country ii. Each of the following KK lines contains five integers [Country 1] [City 1] [Country 2] [City 2] [Price]. This means that, there is a bi-directional flight route between the [City 1] in [Country 1] and the [City 2] in [Country 2], and its price is [Price].

Note that cities in each country are numbered from 1, and the cities whose city number is smaller or equal to F_iF\_i have international airports. That is, if there is a flight route between the city c_1c\_1 in the country n_1n\_1 and the city c_2c\_2 in the country n_2n\_2 with n_1n_2n\_1 \neq n\_2, it must be c_1F_n_1c\_1 \leq F\_{n\_1} and c_2F_n_2c\_2 \leq F\_{n\_2}. You can assume that there's no flight route which departs from one city and flies back to the same city, and that at most one flight route exists in this world for each pair of cities.

The following constraints hold for each dataset:

  • 1N151 \leq N \leq 15
  • 1M_i151 \leq M\_i \leq 15
  • 1F_i41 \leq F\_i \leq 4
  • sum(F_i)15sum(F\_i) \leq 15
  • 1Price10,0001 \leq Price \leq 10,000

출력

Print a line that contains a single integer representing the minimum price to make a world trip.

If such a trip is impossible, print -1 instead.