#include <bits/stdc++.h>
using namespace std;
const long long N = 511;
long long n, m, k, h;
long long a[N][N];
long long b[N][N];
long long ax[N];
long long bx[N];
long long ay[N];
long long by[N];
signed main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= m; j++) {
      cin >> a[i][j];
    }
  }
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= m; j++) {
      cin >> b[i][j];
    }
  }
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= m; j++) {
      ay[i] = ay[i] + a[i][j];
      by[i] = by[i] + b[i][j];
    }
    ay[i] = ay[i] % 2;
    by[i] = by[i] % 2;
    while (ay[i] < 0) {
      ay[i] += 2;
    }
    while (by[i] < 0) {
      by[i] += 2;
    }
    if (ay[i] != by[i]) {
      cout << "No"
           << "\n";
      return 0;
    }
  }
  for (long long j = 1; j <= m; j++) {
    for (long long i = 1; i <= n; i++) {
      ax[j] = ax[j] + a[i][j];
      bx[j] = bx[j] + b[i][j];
    }
    ax[j] = ax[j] % 2;
    bx[j] = bx[j] % 2;
    while (ax[j] < 0) {
      ax[j] += 2;
    }
    while (bx[j] < 0) {
      bx[j] += 2;
    }
    if (ax[j] != bx[j]) {
      cout << "No"
           << "\n";
      return 0;
    }
  }
  cout << "Yes"
       << "\n";
  return 0;
}
