#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  int a[n][m];
  int b[n][m];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      scanf("%d", &a[i][j]);
    }
  }
  int countT = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      scanf("%d", &b[i][j]);
      if (a[i][j] != b[i][j]) {
        countT++;
      }
    }
  }
  string ans = "No";
  bool flag = false;
  if (true || countT % 4 == 0) {
    for (int i = 0; i < n; i++) {
      int count = 0;
      for (int j = 0; j < m; j++) {
        if (a[i][j] != b[i][j]) {
          count++;
        }
      }
      if (count % 2 == 1) {
        flag = true;
        break;
      }
    }
    for (int i = 0; i < m && !flag; i++) {
      int count = 0;
      for (int j = 0; j < n; j++) {
        if (a[j][i] != b[j][i]) {
          count++;
        }
      }
      if (count % 2 == 1) {
        flag = true;
        break;
      }
    }
    if (!flag) {
      ans = "Yes";
    }
  }
  cout << ans << endl;
  return 0;
}
