#include <bits/stdc++.h>
using namespace std;
const int N = 500 + 5;
int a[N][N], b[N][N], row[N], col[N];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> 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]) {
        row[i]++;
        col[j]++;
      }
    }
  }
  int flag = 0;
  for (int i = 0; i < n; i++) {
    if (row[i] & 1) flag = 1;
  }
  for (int i = 0; i < m; i++) {
    if (col[i] & 1) flag = 1;
  }
  if (flag)
    cout << "No" << endl;
  else
    cout << "Yes" << endl;
  return 0;
}
