#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  ;
  bool resp = true;
  int mat[600][600], dest[600][600];
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) cin >> mat[i][j];
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) cin >> dest[i][j];
  }
  for (int i = 0; i < n; i++) {
    int linhas = 0;
    int colunas = 0;
    for (int j = 0; j < m; j++) {
      if (mat[i][j] != dest[i][j]) linhas++;
    }
    if (linhas % 2 == 1) resp = false;
  }
  for (int i = 0; i < m; i++) {
    int linhas = 0;
    int colunas = 0;
    for (int j = 0; j < n; j++) {
      if (mat[j][i] != dest[j][i]) linhas++;
    }
    if (linhas % 2 == 1) resp = false;
  }
  if (resp)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}
