#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  int a[n + 1][m + 1], b[n + 1][m + 1];
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> a[i][j];
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> b[i][j];
    }
  }
  int oa = 0, ob = 0, za = 0, zb = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (a[i][j] == 1) {
        oa++;
      } else if (a[i][j] == 0) {
        za++;
      }
      if (b[i][j] == 1) {
        ob++;
      } else if (b[i][j] == 0) {
        zb++;
      }
    }
    if (abs(oa - ob) % 2 != 0 || abs(za - zb) % 2 != 0) {
      cout << "No";
      return 0;
    }
  }
  oa = ob = za = zb = 0;
  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= n; j++) {
      if (a[j][i] == 1) {
        oa++;
      } else if (a[j][i] == 0) {
        za++;
      }
      if (b[j][i] == 1) {
        ob++;
      } else if (b[j][i] == 0) {
        zb++;
      }
    }
    if (abs(oa - ob) % 2 != 0 || abs(za - zb) % 2 != 0) {
      cout << "No";
      return 0;
    }
  }
  cout << "Yes";
}
