#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll inf = 1e18;
const int N = 5 * 1e2 + 10;
ll res;
ll a[N][N], b[N][N];
void solve() {
  ll n, m;
  cin >> n >> 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 >> b[i][j];
    }
  }
  for (int i = 0; i < n; ++i) {
    res = 0;
    for (int j = 0; j < m; ++j) {
      if (a[i][j] != b[i][j]) res++;
    }
    if (res % 2) {
      cout << "NO";
      return;
    }
  }
  for (int i = 0; i < m; ++i) {
    res = 0;
    for (int j = 0; j < n; ++j) {
      if (a[j][i] != b[j][i]) res++;
    }
    if (res % 2) {
      cout << "NO";
      return;
    }
  }
  cout << "YES";
}
int main(int argc, char const *argv[]) {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  ll t = 1;
  while (t--) {
    solve();
  }
}
