#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  int a[n][m], b[n][m];
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      cin >> a[i][j];
    }
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      cin >> b[i][j];
    }
  }
  int r[n], c[m];
  memset(r, 0, sizeof r);
  memset(c, 0, sizeof c);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      if (a[i][j] != b[i][j]) ++r[i], ++c[j];
    }
  }
  bool ok = true;
  for (int i = 0; i < n; ++i) ok &= (r[i] % 2 == 0);
  for (int j = 0; j < m; ++j) ok &= (c[j] % 2 == 0);
  cout << (ok ? "Yes" : "No") << '\n';
}
