#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  bool x;
  cin >> n >> m;
  vector<bool> rowAXor(n);
  vector<bool> rowBXor(n);
  vector<bool> colAXor(m);
  vector<bool> colBXor(m);
  int totalBXor = 0, totalAXor = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      cin >> x;
      totalAXor ^= x;
      rowAXor[i] = (rowAXor[i] ^ x);
      colAXor[j] = (x ^ colAXor[j]);
    }
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      cin >> x;
      totalBXor ^= x;
      rowBXor[i] = (rowBXor[i] ^ x);
      colBXor[j] = (x ^ colBXor[j]);
    }
  }
  bool isValid = (totalAXor == totalBXor);
  for (int i = 0; i < n; ++i) {
    isValid &= (rowAXor[i] == rowBXor[i]);
  }
  for (int i = 0; i < m; ++i) {
    isValid &= (colBXor[i] == colAXor[i]);
  }
  if (isValid) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}
