#include <bits/stdc++.h>
using namespace std;
long long n, m;
long long sum = 0;
long long a[500][500];
long long b[500][500];
long long v[500];
long long h[500];
int main() {
  cin >> 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];
    }
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      if (a[i][j] != b[i][j]) {
        v[j]++;
        h[i]++;
      }
    }
  }
  bool yes = true;
  for (int j = 0; j < m; ++j) {
    if (v[j] % 2 != 0) {
      yes = false;
      break;
    }
  }
  for (int j = 0; j < n; ++j) {
    if (h[j] % 2 != 0) {
      yes = false;
      break;
    }
  }
  if (yes) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}
