Buying Books 2

No attempts yetTime limit1sMemory limit256 MB

Problem

N people want to buy the same book. The people are numbered 1 to N, and person j wants AjA_j copies. M online stores sell the book. The stores are numbered 1 to M, and store i holds BiB_i copies.

These N people are the only buyers, and the total number of copies the stores hold equals the total number of copies the people want.

How many copies one person buys from one store is limited. Person j can buy at most CijC_{ij} copies from store i. Given every purchase limit between a store and a person, write a program that finds the largest number of copies that can be bought.

Input

The first line contains the number of people N and the number of online stores M. (1N,M1001 \le N, M \le 100)

The second line contains A1,A2,,ANA_1, A_2, \dots, A_N, the number of copies each person wants. (1Aj1001 \le A_j \le 100)

The third line contains B1,B2,,BMB_1, B_2, \dots, B_M, the number of copies each store holds. (1Bi1001 \le B_i \le 100)

Each of the next M lines contains N numbers and gives the purchase limits. The j-th number on the i-th line is CijC_{ij}, the largest number of copies person j can buy from store i. (0Cij1000 \le C_{ij} \le 100)

A1++AN=B1++BMA_1 + \dots + A_N = B_1 + \dots + B_M holds.

Output

Print the largest number of copies that can be bought.