#include <bits/stdc++.h>
using namespace std;
int n, m;
bool get(vector<vector<int> > &a, vector<vector<int> > &b) {
  for (int i = 1; i <= (int)(n - 1); ++i)
    for (int j = 1; j <= (int)(m - 1); ++j) {
      if (a[i][j] != b[i][j]) {
        a[i][j] ^= 1;
        a[0][j] ^= 1;
        a[i][0] ^= 1;
        a[0][0] ^= 1;
      }
    }
  return a == b;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.precision(10);
  cout << fixed;
  while (cin >> n >> m) {
    vector<vector<int> > a(n, vector<int>(m)), b(n, vector<int>(m));
    for (int i = 0; i < (int)(n); ++i)
      for (int j = 0; j < (int)(m); ++j) cin >> a[i][j];
    for (int i = 0; i < (int)(n); ++i)
      for (int j = 0; j < (int)(m); ++j) cin >> b[i][j];
    cout << (get(a, b) ? "YES" : "NO") << endl;
  }
  return 0;
}
