#include <bits/stdc++.h>
using namespace std;
long long modpow(long long a, long long b,
                 long long mod = (long long)(1e9 + 7)) {
  if (!b) return 1;
  a %= mod;
  return modpow(a * a % mod, b / 2, mod) * (b & 1 ? a : 1) % mod;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int DEBUG = 1;
const int mxn = 500;
int n, m;
int a[mxn][mxn], b[mxn][mxn];
void solve() {
  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++) {
    int bit = 0;
    for (int j = 0; j < m; j++) bit ^= a[i][j], bit ^= b[i][j];
    if (bit) {
      cout << "No" << endl;
      return;
    }
  }
  for (int j = 0; j < m; j++) {
    int bit = 0;
    for (int i = 0; i < n; i++) bit ^= a[i][j], bit ^= b[i][j];
    if (bit) {
      cout << "No" << endl;
      return;
    }
  }
  cout << "Yes" << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  while (cin >> n >> m) solve();
  return 0;
}
