You're in a class of students, each with a current status s_i. If any student's status becomes negative, they're expelled.
A special -day test is announced where, each day, every student votes to reduce the status of a specific classmate by . Votes are stored in an n \times m grid , where V_{i,j} means that on day , student votes for student V_{i,j}.
To prevent any expulsions, you can pay to change specific votes. Changing student 's vote on day costs C_{i,j} coins, and you can redirect this vote to any student you choose.
Determine the minimum total cost required to keep every student's status non-negative throughout the test.
The first line contains two integers, and (1 \leq n, m \leq 500) — the number of students and the number of days.
The second line contains integers s_1, s_2, \dots, s_n (0 \leq s_i \leq n\times m) — the initial status of each student.
The next lines describe the voting matrix , where the -th line contains integers V_{i,1}, V_{i,2}, \dots, V_{i,m} (1 \leq V_{i,j} \leq n). Each V_{i,j} indicates that on day , student votes for student V_{i,j}.
The next lines describe the cost matrix , where the -th line contains integers C_{i,1}, C_{i,2}, \dots, C_{i,m} (0 \leq C_{i,j} \leq 5\cdot 10^4). Each C_{i,j} represents the cost to change student 's vote on day .
Print a single integer — the minimum total cost in coins required to ensure that no student's status becomes negative by the end of the -day test. If it's impossible to prevent any student from being expelled, print .
Example 1
Example 2
In the first sample, we may change the vote of the second student on the first day. It costs us coins, and if we redirect his vote to the third student, no one would be expelled. It may be shown that it is the minimal possible answer.
In the second sample, we can prove that there is no solution.
( points): C_{i,j}=0;
( points): m=1;
( points): V_{i, j}=1;
( points): n, m\le 100;
( points): no additional constraints.