#include <bits/stdc++.h>
using namespace std;
int A[510][510], B[510][510];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m;
  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++) {
    int ct = 0;
    for (int j = 0; j < m; j++) {
      if (A[i][j] != B[i][j]) ct++;
    }
    if (ct % 2) {
      cout << "NO\n";
      return 0;
    }
  }
  for (int j = 0; j < m; j++) {
    int ct = 0;
    for (int i = 0; i < n; i++) {
      if (A[i][j] != B[i][j]) ct++;
    }
    if (ct % 2) {
      cout << "NO\n";
      return 0;
    }
  }
  cout << "YES\n";
}
