#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n, m;
  cin >> n >> m;
  long long a[n][m], b[n][m], res[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++) {
    for (int j = 0; j < m; j++)
      if (a[i][j] != b[i][j])
        res[i][j] = 1;
      else
        res[i][j] = 0;
  }
  bool flag = false;
  long long sum_t = 0;
  for (int i = 0; i < n; i++) {
    long long sum_r = 0;
    for (int j = 0; j < m; j++) {
      sum_r += res[i][j];
      sum_t += res[i][j];
    }
    if (sum_r % 2 != 0) {
      flag = true;
      break;
    }
  }
  for (int j = 0; j < m; j++) {
    long long sum_c = 0;
    for (int i = 0; i < n; i++) {
      sum_c += res[i][j];
    }
    if (sum_c % 2 != 0) {
      flag = true;
      break;
    }
  }
  if (flag)
    cout << "No";
  else
    cout << "Yes";
  return 0;
}
