#include <bits/stdc++.h>
using namespace std;
long long gcd(long long x, long long y) {
  if (y == 0) return x;
  return gcd(y, x % y);
}
long long absol(long long x) {
  if (x < 0) {
    return -x;
  }
  return x;
}
priority_queue<pair<long long, long long>, vector<pair<long long, long long> >,
               greater<pair<long long, long long> > >
    pq;
long long expo(long long b, long long n, long long m) {
  long long r, p;
  p = 1;
  b = b % m;
  while (n > 0) {
    r = n % 2;
    if (r == 1) p = ((p % m) * (b % m)) % m;
    b = ((b % m) * (b % m)) % m;
    n = n / 2;
  }
  return (p % m);
}
long long divide1(long long a, long long b, long long m) {
  long long r, p, n;
  p = a % m;
  n = m - 2;
  while (n > 0) {
    r = n % 2;
    if (r == 1) p = ((p % m) * (b % m)) % m;
    b = ((b % m) * (b % m)) % m;
    n = n / 2;
  }
  return (p % m);
}
long long mat1[600][600], mat2[600][600], diff1[600][600], coun[609],
    coun1[600];
int main(int argc, char const *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL), cout.tie(NULL);
  long long n, m;
  cin >> n >> m;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      cin >> mat1[i][j];
    }
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      cin >> mat2[i][j];
      if (mat1[i][j] == mat2[i][j]) {
        diff1[i][j] = 0;
      } else
        diff1[i][j] = 1;
      coun[i] += diff1[i][j];
      coun1[j] += diff1[i][j];
    }
  }
  for (int i = 0; i < n; ++i) {
    if (coun[i] & 1) {
      cout << "No"
           << "\n";
      return 0;
    }
  }
  for (int i = 0; i < m; ++i) {
    if (coun1[i] & 1) {
      cout << "No"
           << "\n";
      return 0;
    }
  }
  cout << "Yes"
       << "\n";
  return 0;
}
