#include <bits/stdc++.h>
using namespace std;
using lli = int_fast64_t;
using ulli = uint_fast64_t;
template <typename T>
T ncr(T left, T right) {
  right = min(left - right, right);
  T ans = 1;
  for (T i = 1; i <= right; i++) {
    ans = ans * (left - right + i) / i;
  }
  return ans;
}
const lli MOD = 1000000007;
const lli LIMIT = 10000000000000000 * 5;
const int tenfive = 100000;
int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<int>> A(N, vector<int>(M));
  vector<vector<int>> B(N, vector<int>(M));
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) {
      cin >> A[i][j];
    }
  }
  vector<vector<int>> need = A;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) {
      cin >> B[i][j];
      need[i][j] ^= B[i][j];
    }
  }
  bool needwide = false;
  int save = -1;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) {
      if (need[i][j]) {
        if (needwide) {
          if (i == N - 1) {
            cout << "No" << endl;
            return 0;
          }
          need[i][save] ^= 1;
          need[i + 1][save] ^= 1;
          need[i][j] ^= 1;
          need[i + 1][j] ^= 1;
        } else {
          save = j;
        }
        needwide = !needwide;
      }
    }
    if (needwide) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}
