#include <bits/stdc++.h>
using namespace std;
int hang[505], lie[505];
int main() {
  int n, m;
  cin >> n >> m;
  int a[505][505], b[505][505];
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) scanf("%d", &a[i][j]);
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) scanf("%d", &b[i][j]);
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (a[i][j] != b[i][j]) hang[i]++;
    }
  }
  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= n; j++) {
      if (a[j][i] != b[j][i]) lie[i]++;
    }
  }
  int flag = 0;
  for (int i = 1; i <= n; i++) {
    if (hang[i] % 2 != 0) {
      flag = 1;
      break;
    }
  }
  if (!flag) {
    for (int i = 1; i <= m; i++) {
      if (lie[i] % 2 != 0) {
        flag = 1;
        break;
      }
    }
  }
  if (flag)
    cout << "No" << endl;
  else
    cout << "Yes" << endl;
  return 0;
}
