#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, flag = 1;
  cin >> n >> m;
  int a[n][m], b[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 - 1; i++) {
    for (int j = 0; j < m - 1; j++) {
      if (a[i][j] != 0) {
        a[i][j] = !a[i][j];
        a[i][j + 1] = !a[i][j + 1];
        a[i + 1][j] = !a[i + 1][j];
        a[i + 1][j + 1] = !a[i + 1][j + 1];
      }
      if (b[i][j] != 0) {
        b[i][j] = !b[i][j];
        b[i][j + 1] = !b[i][j + 1];
        b[i + 1][j] = !b[i + 1][j];
        b[i + 1][j + 1] = !b[i + 1][j + 1];
      }
    }
  }
  for (int i = 0; i < n; i++) {
    if (a[i][m - 1] != b[i][m - 1]) {
      flag = 0;
    }
  }
  for (int i = 0; i < m; i++) {
    if (a[n - 1][i] != b[n - 1][i]) {
      flag = 0;
    }
  }
  if (flag == 1) {
    cout << "Yes";
  } else {
    cout << "No";
  }
  return 0;
}
