#include <bits/stdc++.h>
using namespace std;
int n, m;
int mp1[505][505], mp2[505][505];
int e1 = 0, o1 = 0, e2 = 0, o2 = 0;
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> mp1[i][j];
      if (mp1[i][j] == 1) {
        if ((i + j) % 2 == 0)
          e1++;
        else
          o1++;
      }
    }
  }
  int cnt = 0, falg = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> mp2[i][j];
      if (mp2[i][j] != mp1[i][j]) cnt++;
    }
    if (cnt % 2 == 1) falg = 1;
    cnt = 0;
  }
  for (int j = 1; j <= m; j++) {
    for (int i = 1; i <= n; i++) {
      if (mp2[i][j] != mp1[i][j]) cnt++;
    }
    if (cnt % 2 == 1) falg = 1;
    cnt = 0;
  }
  if (!falg) {
    cout << "Yes" << endl;
  } else
    cout << "No" << endl;
}
