#include <bits/stdc++.h>
using namespace std;
template <class c>
struct rge {
  c b, e;
};
template <class c>
rge<c> range(c i, c j) {
  return rge<c>{i, j};
}
template <class c>
auto dud(c* x) -> decltype(cerr << *x, 0);
template <class c>
char dud(...);
struct debug {
  template <class c>
  debug& operator<<(const c&) {
    return *this;
  }
};
const long long int N = 500 + 10;
const long long int INF = 2e9;
long long int MOD = 1e9 + 7;
long long int r[N], c[N];
void solve() {
  long long int n, m;
  cin >> n >> m;
  for (long long int i = 0; i < n; i++) {
    for (long long int j = 0; j < m; j++) {
      long long int x;
      cin >> x;
      r[i] ^= x;
      c[j] ^= x;
    }
  }
  for (long long int i = 0; i < n; i++) {
    for (long long int j = 0; j < m; j++) {
      long long int x;
      cin >> x;
      r[i] ^= x;
      c[j] ^= x;
    }
  }
  for (long long int i = 0; i < n; i++) {
    if (r[i]) {
      cout << "No";
      return;
    }
  }
  for (long long int i = 0; i < m; i++) {
    if (c[i]) {
      cout << "No";
      return;
    }
  }
  cout << "Yes";
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long int t = 1;
  while (t--) solve();
  return 0;
}
