#include <bits/stdc++.h>
using namespace std;
int a[501][501], b[501][501], c[501], r[501], n, m, to1 = 0, to0 = 0;
bool y = 1;
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++) {
      a[i][j] ^= b[i][j];
      c[j] ^= a[i][j];
      r[i] ^= a[i][j];
    }
  }
  for (int i = 0; i < n; i++) {
    if (r[i]) {
      y = 0;
    }
  }
  for (int i = 0; i < m; i++) {
    if (c[i]) {
      y = 0;
    }
  }
  if (y) {
    cout << "Yes\n";
  } else {
    cout << "No\n";
  }
  return 0;
}
