#include<bits/stdc++.h>
using namespace std;
#define int long long
const int MOD = 1e9 + 7;
int n, k, ans = 0;
vector<vector<pair<int, int>>>top;
vector<vector<int>>r, u;
vector<int> cnt, p, pnt;
bool until(){
bool b = false;
for(int i = 1; i <= k; i++){
while(pnt[i] < top[i].size() and p[i] >= top[i][pnt[i]].first){
int id = top[i][pnt[i]].second;
cnt[id]++;
if(cnt[id] == k){
for(int j = 1; j <= k; j++){
p[j] += u[id][j];
}
ans++;
b = true;
}
pnt[i]++;
}
}
return b;
}
signed main(){
cin >> n >> k;
top.resize(n + 1);
r.resize(n + 1, vector<int>(k + 1));
u.resize(n + 1, vector<int>(k + 1));
cnt.resize(n + 1);
p.resize(n + 1);
pnt.resize(n + 1);
for(int i = 1; i <=n; i++){
for(int j = 1; j <= k; j++){
cin >> r[i][j];
top[j].push_back({r[i][j], i});
}
}
for(int i = 1; i <= k; i++){
sort(top[i].begin(), top[i].end());
}
for(int i = 1; i <= n; i++){
for(int j = 1; j <= k; j++){
cin >> u[i][j];
}
}
while(until());
cout << ans;
}