#include <bits/stdc++.h>
using namespace std;
int a[500][500];
int b[500][500];
int main() {
  int n, m;
  cin >> n >> m;
  int e;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> e;
      a[i][j] = e;
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> e;
      b[i][j] = e;
    }
  }
  for (int i = 0; i < n; i++) {
    int f;
    int s = f = 0;
    for (int j = 0; j < m; j++) {
      f += a[i][j];
      s += b[i][j];
    }
    if ((f - s) % 2 != 0) {
      cout << "No" << endl;
      return 0;
    }
  }
  for (int i = 0; i < m; i++) {
    int f;
    int s = f = 0;
    for (int j = 0; j < n; j++) {
      f += a[j][i];
      s += b[j][i];
    }
    if ((f - s) % 2 != 0) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
  return 0;
}
