#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, m;
  cin >> n >> m;
  long long i, j;
  long long a[n][m], b[n][m];
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      cin >> a[i][j];
    }
  }
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      cin >> b[i][j];
    }
  }
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      if (a[i][j] != b[i][j]) {
        long long i1, j1;
        i1 = i + 1;
        while (i1 < n && a[i1][j] == b[i1][j]) {
          i1++;
        }
        j1 = j + 1;
        while (j1 < m && a[i][j1] == b[i][j1]) {
          j1++;
        }
        if (i1 >= n || j1 >= m) {
          cout << "No" << '\n';
          return 0;
        }
        a[i][j] = 1 - a[i][j];
        a[i][j1] = 1 - a[i][j1];
        a[i1][j1] = 1 - a[i1][j1];
        a[i1][j] = 1 - a[i1][j];
      }
    }
  }
  cout << "Yes" << '\n';
  return 0;
}
