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