#include <bits/stdc++.h>
using namespace std;
const long long N = 1e6 + 5;
const long long mod = 1e9 + 7;
bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) {
  return (a.second < b.second);
}
long long powermod(long long x, long long y, long long p) {
  long long res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
bool isprime(int n) {
  if (n <= 1) return false;
  if (n <= 3) return true;
  if (n % 2 == 0 || n % 3 == 0) return false;
  for (int i = 5; i * i <= n; i = i + 6)
    if (n % i == 0 || n % (i + 2) == 0) return false;
  return true;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long n, m;
  cin >> n >> m;
  long long a[n + 1][m + 1];
  long long b[n + 1][m + 1];
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= m; j++) cin >> a[i][j];
  }
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= m; j++) cin >> b[i][j];
  }
  vector<pair<long long, long long>> v;
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= m; j++) {
      if (a[i][j] != b[i][j]) v.push_back({i, j});
    }
  }
  if (v.size() == 1) {
    cout << "No"
         << "\n";
    return 0;
  }
  long long k = 0;
  sort(v.begin(), v.end(), sortbysec);
  long long cnt = 1;
  for (long long i = 1; i < v.size(); i++) {
    if (v[i].second == v[i - 1].second)
      cnt++;
    else {
      if (cnt % 2 != 0) {
        k = 1;
        break;
      }
      cnt = 1;
    }
  }
  sort(v.begin(), v.end());
  cnt = 1;
  for (long long i = 1; i < v.size(); i++) {
    if (v[i].first == v[i - 1].first)
      cnt++;
    else {
      if (cnt % 2 != 0) {
        k = 1;
        break;
      }
      cnt = 1;
    }
  }
  if (k)
    cout << "No"
         << "\n";
  else
    cout << "Yes"
         << "\n";
  return 0;
}
