#include <bits/stdc++.h>
using namespace std;
bool chk(vector<int> a, vector<int> b){
for(int i=0;i<a.size();i++){
if(a[i]<b[i]){
return false;
}
}
return true;
}
int main() {
// your code goes here
int n,k;
cin >> n >> k;
std::vector<vector<int>> r(n, vector<int>(k));
std::vector<vector<int>> u(n, vector<int>(k));
for(int i=0;i<n;i++){
for(int j=0;j<k;j++){
cin >> r[i][j];
}
}
for(int i=0;i<n;i++){
for(int j=0;j<k;j++){
cin >> u[i][j];
}
}
int ans = 0;
bool update = false;
vector<bool> done(n, false);
vector<int> cur(n, 0);
while(true){
update = false;
for(int i=0;i<n;i++){
if(done[i]!=true){
if(chk(cur, r[i])){
for(int j=0;j<k;j++){
cur[j]=cur[j]+u[i][j];
}
ans++;
update = true;
done[i]=true;
}
}
}
if(update!=true){
break;
}
}
cout << ans;
return 0;
}