#include<iostream>
using namespace std;
int main()
{
int N,M;
int *m,*n,*k;
while(cin>>M)
{
if (M ==0)break;
cin>>N;
int sum = 0,out = 0;
m = new int[M*N];
n = new int[M*N];
k = new int[M*N];
for (int i=0;i<M*N;i++)
{
cin>>m[i];
}
for (int i=0;i<M*N;i++)
{
cin>>n[i];
}
for (int i=0;i<M*N;i++)
{
k[i] = m[i]+n[i];
}
for(int i =0;i<M;i++)
{
for (int j=0;j<N;j++)
{
sum = sum + k[i*N+j];
}
if (sum ==0)
{
out = out+1;
}
else
sum = 0;
}
sum = 0;
for(int i =0;i<N;i++)
{
for (int j=0;j<M;j++)
{
sum = sum + k[i+j*N];
}
if (sum ==0)
{
out = out+1;
}
else
sum = 0;
}
cout<<out<<endl;
}
return 0;
}
using namespace std;
int main()
{
int N,M;
int *m,*n,*k;
while(cin>>M)
{
if (M ==0)break;
cin>>N;
int sum = 0,out = 0;
m = new int[M*N];
n = new int[M*N];
k = new int[M*N];
for (int i=0;i<M*N;i++)
{
cin>>m[i];
}
for (int i=0;i<M*N;i++)
{
cin>>n[i];
}
for (int i=0;i<M*N;i++)
{
k[i] = m[i]+n[i];
}
for(int i =0;i<M;i++)
{
for (int j=0;j<N;j++)
{
sum = sum + k[i*N+j];
}
if (sum ==0)
{
out = out+1;
}
else
sum = 0;
}
sum = 0;
for(int i =0;i<N;i++)
{
for (int j=0;j<M;j++)
{
sum = sum + k[i+j*N];
}
if (sum ==0)
{
out = out+1;
}
else
sum = 0;
}
cout<<out<<endl;
}
return 0;
}