#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  int a[n][m];
  int c[m], d[n];
  for (int i = 0; i < n; i++) {
    d[i] = 0;
    for (int j = 0; j < m; j++) {
      c[j] = 0;
      cin >> a[i][j];
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      int b;
      cin >> b;
      if (b != a[i][j]) c[j]++, d[i]++;
    }
  }
  if (n == 1 || m == 1) {
    for (int i = 0; i < m; i++)
      if (c[i]) {
        cout << "No" << endl;
        return 0;
      }
    for (int i = 0; i < n; i++)
      if (d[i]) {
        cout << "No" << endl;
        return 0;
      }
  }
  for (int i = 0; i < m; i++)
    if (c[i] % 2) {
      cout << "No" << endl;
      return 0;
    }
  for (int i = 0; i < n; i++)
    if (d[i] % 2) {
      cout << "No" << endl;
      return 0;
    }
  cout << "Yes" << endl;
  return 0;
}
