#include <iostream>
using namespace std;
int x[500][500];
int main(){
int n, m, p;
cin >> n >> m;
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
cin >> x[i][j];
unsigned long long v = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cin >> p;
if (p) v += x[i][j];
}
}
cout << v;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKaW50IHhbNTAwXVs1MDBdOwppbnQgbWFpbigpewoJaW50IG4sIG0sIHA7CgljaW4gPj4gbiA+PiBtOwoJZm9yIChpbnQgaSA9IDA7IGkgPCBuOyBpKyspCgkJZm9yIChpbnQgaiA9IDA7IGogPCBtOyBqKyspCgkJCWNpbiA+PiB4W2ldW2pdOwoJdW5zaWduZWQgbG9uZyBsb25nIHYgPSAwOwoJZm9yIChpbnQgaSA9IDA7IGkgPCBuOyBpKyspIHsKCQlmb3IgKGludCBqID0gMDsgaiA8IG07IGorKykgewoJCQljaW4gPj4gcDsKCQkJaWYgKHApIHYgKz0geFtpXVtqXTsKCQl9CiAgICB9Cgljb3V0IDw8IHY7Cn0g