#include <bits/stdc++.h>
using namespace std;
long long int A[600][600];
long long int B[600][600];
long long int d[600][600];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int n, m;
  cin >> n >> m;
  for (long long int i = 0; i < n; i++) {
    for (long long int j = 0; j < m; j++) {
      cin >> A[i][j];
    }
  }
  for (long long int i = 0; i < n; i++) {
    for (long long int j = 0; j < m; j++) {
      cin >> B[i][j];
    }
  }
  memset(d, 0, sizeof d);
  for (long long int i = 0; i < n; i++) {
    for (long long int j = 0; j < m; j++) {
      d[i][j] = A[i][j] != B[i][j];
    }
  }
  for (long long int row = 0; row < n; row++) {
    long long int s = 0;
    for (long long int col = 0; col < m; col++) {
      s += d[row][col];
    }
    if (s % 2) {
      cout << "No" << endl;
      return 0;
    }
  }
  for (long long int col = 0; col < m; col++) {
    long long int s = 0;
    for (long long int row = 0; row < n; row++) {
      s += d[row][col];
    }
    if (s % 2) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}
