#include <bits/stdc++.h>
using std::abs;
using std::bitset;
using std::cerr;
using std::cin;
using std::cout;
using std::map;
using std::max;
using std::min;
using std::pair;
using std::set;
using std::sort;
using std::string;
using std::swap;
using std::unordered_map;
using std::unordered_set;
using std::vector;
using ll = long long;
using uint = unsigned int;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using ull = unsigned long long;
using ld = long double;
template <typename T>
void _dbg(const char* s, T h) {
  cerr << s << " = " << h << "\n";
}
template <typename T, typename... Ts>
void _dbg(const char* s, T h, Ts... t) {
  int b = 0;
  while (((b += *s == '(') -= *s == ')') != 0 || *s != ',') cerr << *s++;
  cerr << " = " << h << ",";
  _dbg(s + 1, t...);
}
struct init {
  init() {
    cin.tie(0);
    std::iostream::sync_with_stdio(0);
    cout << std::fixed << std::setprecision(10);
    cerr << std::fixed << std::setprecision(5);
  }
  ~init() {}
} init;
template <typename T, typename U>
void upx(T& x, U y) {
  if (x < y) x = y;
}
template <typename T, typename U>
void upn(T& x, U y) {
  if (x > y) x = y;
}
const ll N = 555;
ll a[N][N];
ll b[N][N];
ll r[N], c[N];
int32_t main() {
  ll n, m;
  cin >> n >> m;
  for (ll i = 0; i < (n); ++i) {
    for (ll j = 0; j < (m); ++j) {
      cin >> a[i][j];
      r[i] ^= a[i][j];
      c[j] ^= a[i][j];
    }
  }
  for (ll i = 0; i < (n); ++i) {
    for (ll j = 0; j < (m); ++j) {
      cin >> b[i][j];
      r[i] ^= b[i][j];
      c[j] ^= b[i][j];
    }
  }
  ll ok = 1;
  for (ll i = 0; i < (n); ++i) ok &= r[i] == 0;
  for (ll i = 0; i < (m); ++i) ok &= c[i] == 0;
  if (ok)
    cout << "Yes\n";
  else
    cout << "No\n";
  return 0;
}
