#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, m, a;
  cin >> n >> m;
  vector<vector<int>> A(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 >> a;
      if (a != A[i][j])
        A[i][j] = 1;
      else
        A[i][j] = 0;
    }
  }
  for (int i = 0; i < n - 1; ++i) {
    int cnt = 0;
    for (int j = 0; j < m; ++j) {
      if (A[i][j]) {
        A[i + 1][j] = 1 - A[i + 1][j];
        ++cnt;
      }
    }
    if (cnt & 1) {
      cout << "No";
      return 0;
    }
  }
  for (int j = 0; j < m; ++j) {
    if (A[n - 1][j]) {
      cout << "No";
      return 0;
    }
  }
  cout << "Yes";
  return 0;
}
