#include <bits/stdc++.h>
using namespace std;
bool sortinrev(long long x, long long y) { return x > y; }
void swap(long long* a, long long* b) {
  long long temp = *a;
  *a = *b;
  *b = temp;
}
long long div_ceil(long long a, long long b) { return (a + b - 1) / b; }
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long lcm(long long a, long long b) { return (a / gcd(a, b)) * b; }
const int MOD = 1000 * 1000 * 1000 + 7;
const long long INF = 1e18L + 5;
long long fpow(long long a, long long b) {
  if (b == 0) return 1;
  if (b % 2 == 1) {
    return fpow(a, b - 1) * a % MOD;
  } else {
    long long b2 = fpow(a, b / 2) % MOD;
    return b2 * b2 % MOD;
  }
}
const int nax = 200005;
const int N = int(1e5) + 5;
void solve() {
  long long n, m;
  cin >> n >> m;
  vector<vector<long long>> matA(n + 1, vector<long long>(m + 1));
  vector<vector<long long>> matB(n + 1, vector<long long>(m + 1));
  long long sum1 = 0, sum2 = 0;
  for (long long i = 0; i < n; ++i) {
    for (long long j = 0; j < m; ++j) {
      cin >> matA[i][j];
      sum1 += 0;
    }
  }
  for (long long i = 0; i < n; ++i) {
    for (long long j = 0; j < m; ++j) {
      cin >> matB[i][j];
      sum2 += 0;
    }
  }
  if (sum1 % 2 != sum2 % 2) {
    cout << "NO\n";
    return;
  }
  bool flag = 1;
  long long cnt1 = 0, cnt2 = 0;
  for (long long i = 0; i < n; ++i) {
    long long cnt11 = 0, cnt12 = 0;
    for (long long j = 0; j < m; ++j) {
      cnt11 += matA[i][j];
      cnt12 += matB[i][j];
    }
    if (cnt11 % 2 != cnt12 % 2) {
      flag = 0;
      break;
    }
  }
  for (long long j = 0; j < m; ++j) {
    long long cnt21 = 0, cnt22 = 0;
    for (long long i = 0; i < n; ++i) {
      cnt21 += matA[i][j];
      cnt22 += matB[i][j];
    }
    if (cnt21 % 2 != cnt22 % 2) {
      flag = 0;
      break;
    }
  }
  if (flag)
    cout << "YES\n";
  else
    cout << "NO\n";
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  long long T = 1;
  while (t--) {
    cerr << "TEST-CASE #" << T << "\n";
    solve();
    T++;
    cerr << "\n";
  }
  cerr << "\nI am Winning";
  cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
}
