#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int> > a(n, vector<int>(m)), b(n, vector<int>(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];
  vector<int> cr(n, 0), cc(m, 0);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      if (a[i][j] != b[i][j]) {
        cr[i]++;
        cc[j]++;
      }
  bool check = true;
  for (int i = 0; i < n; i++)
    if (cr[i] % 2 == 1) {
      check = false;
      break;
    }
  if (check)
    for (int i = 0; i < m; i++)
      if (cc[i] % 2 == 1) {
        check = false;
        break;
      }
  if (check)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}
