#include <bits/stdc++.h>
using namespace std;
long long n, m;
bool remove(vector<vector<long long> > &C, long long a, long long b) {
  vector<long long> A, B;
  C[a][b] = 0;
  for (long long i = a + 1; i < n; i++) {
    if (C[i][b] == 1) {
      A.push_back(i);
    }
  }
  for (long long j = b + 1; j < m; j++) {
    if (C[a][j]) {
      B.push_back(j);
    }
  }
  for (long long i = 0; i < A.size(); i++) {
    for (long long j = 0; j < B.size(); j++) {
      if (C[A[i]][B[j]] == 1) {
        C[A[i]][B[j]] = 0;
        C[A[i]][b] = 0;
        C[a][B[j]] = 0;
        return true;
      }
    }
  }
  if (A.empty() || B.empty()) return false;
  C[A[0]][B[0]] = 1;
  C[A[0]][b] = 0;
  C[a][B[0]] = 0;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> m;
  long long A[n][m], B[n][m];
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) {
      cin >> A[i][j];
    }
  }
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) {
      cin >> B[i][j];
    }
  }
  vector<vector<long long> > C(n, vector<long long>(m));
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) {
      if (A[i][j] != B[i][j]) {
        C[i][j] = 1;
      } else {
        C[i][j] = 0;
      }
    }
  }
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) {
      if (C[i][j] == 1) {
        if (!remove(C, i, j)) {
          cout << "NO";
          return 0;
        }
      }
    }
  }
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) {
      if (C[i][j] == 1) {
        cout << "NO";
        return 0;
      }
    }
  }
  cout << "YES";
  return 0;
}
