// https://szkopul.edu.pl/problemset/problem/9Xg3SiF9DZ-Xn65OWbu9B42J/site/?key=statement
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ar std::array
constexpr int sizik = 1000 * 1001;
int n, m;
typedef std::pair<int, int> _pr;
std::vector<int> liczniki;
ar<int, sizik> c, s, curr;
void sort_this_____() {
std::sort(liczniki.begin(), liczniki.end(), [](const int& a, const int& b) {
if (c[a] > c[b]) {
return true;
} else if (c[a] == c[b]) {
return curr[a] < curr[b];
} else {
return false;
}
});
}
void print_liczniki() {
std::cout << "liczniki ~> \n";
for (int i = 0; i < n; i++) {
std::cout << liczniki[i] << ' ';
}
std::cout << '\n';
}
int32_t main() {
std::ios_base::sync_with_stdio(0);
std::cin.tie(0);
std::cout.tie(0);
std::cin >> n >> m;
for (int i = 0; i < n; i++) {
std::cin >> c[i];
}
for (int i = 0; i < n; i++) {
std::cin >> s[i];
curr[i] = s[i];
}
for (int i = 0; i < n; i++) {
liczniki.push_back(i);
}
sort_this_____();
for (int i = 0; i < m; i++) {
std::multiset<int> o;
for (int j = 0; j < n; j++) {
int a;
std::cin >> a;
o.insert(a);
}
for (int i = 0; i < n; i++) {
int a = liczniki[i];
auto ptr = o.lower_bound(curr[a]);
if (ptr == o.end()) {
std::cout << "NIE\n";
return 0;
}
curr[a] = *ptr;
o.erase(ptr);
}
sort_this_____();
}
int ans = 0;
for (int i = 0; i < n; i++) {
ans += c[i] * (curr[i] - s[i]);
}
std::cout << ans << '\n';
return 0;
}