#include <bits/stdc++.h>
using namespace std;
int n, m;
bool ma[501][501];
bool diff[501][501];
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) cin >> ma[i][j];
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      cin >> diff[i][j];
      diff[i][j] = diff[i][j] != ma[i][j];
    }
  bool duar = true;
  for (int i = 0; i < n; i++) {
    int jmlbeda = 0;
    for (int j = 0; j < m; j++) {
      if (diff[i][j]) jmlbeda++;
    }
    duar &= duar && (jmlbeda % 2 == 0);
  }
  for (int i = 0; i < m; i++) {
    int jmlbeda = 0;
    for (int j = 0; j < n; j++) {
      if (diff[j][i]) jmlbeda++;
    }
    duar &= jmlbeda % 2 == 0;
  }
  if (duar)
    cout << "Yes\n";
  else
    cout << "No\n";
}
