#include <iostream>
using namespace std;
struct matrix {
    int data[10][10];
    int row;
    int col;
    matrix(int r, int c) {
        row = r;
        col = c;
    }
    matrix operator+(matrix B);
};
matrix matrix::operator+(matrix B) {
    matrix ans = matrix(row, col);
    for (int i = 0; i < row; i++)
        for (int j = 0; j < col; j++) {
            ans.data[i][j] = data[i][j] + B.data[i][j];
        }
    return ans;
}
int zero(matrix A) {
    int zero = A.row + A.col;
    for (int i = 0; i < A.row; i++) {
        for (int j = 0; j < A.col; j++) {
            if (A.data[i][j] != 0) {
                zero--;
                break;
            }
        }
    }
    for (int i = 0; i < A.col; i++) {
        for (int j = 0; j < A.row; j++) {
            if (A.data[j][i] != 0) {
                zero--;
                break;
            }
        }
    }
    return zero;
}
int main() {
    int row, col;
    while (cin >> row >> col) { // 注意 while 处理多个 case
        // cout << a + b << endl;
        matrix A =  matrix(row, col);
        matrix B =matrix(row,col);
        for (int i = 0; i < row; i++) {
            for (int j = 0; j < col; j++) {
                int temp;
                cin >> temp;
                A.data[i][j] = temp;
            }
        }
        for (int i = 0; i < row; i++) {
            for (int j = 0; j < col; j++) {
                int temp;
                cin >> temp;
                B.data[i][j] = temp;
            }
        }
        cout<<zero(A+B)<<endl;
    }
}
// 64 位输出请用 printf("%lld")