#include <bits/stdc++.h>
using namespace std;
int pr[1000007];
bool isnotprime(long long x) {
  if (x == 1) return 1;
  if (x == 2) return 0;
  if (x % 2 == 0) return 1;
  return (pr[x / 64] & (1 << ((x >> 1) & 31)));
}
void sieve(long long n) {
  for (long long i = 3; i * i <= n; i += 2) {
    if (!isnotprime(i))
      for (long long j = i * i, k = i << 1; j < n; j += k)
        pr[j / 64] |= (1 << ((j >> 1) & 31));
  }
}
long long fpow(long long x, long long y) {
  x = x % 1000000007;
  long long res = 1;
  while (y) {
    if (y & 1) res = res * x;
    res %= 1000000007;
    y = y >> 1;
    x = x * x;
    x %= 1000000007;
  }
  return res;
}
long long inv(long long a, long long m) {
  long long c = m;
  long long y = 0, x = 1;
  if (m == 1) return 0;
  while (a > 1) {
    long long q = a / m;
    long long t = m;
    m = a % m, a = t;
    t = y;
    y = x - q * y;
    x = t;
  }
  if (x < 0) x += c;
  return x;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n, m;
  cin >> n >> m;
  long long a[n][m], b[n][m], hx[n], hy[m], c = 0;
  ;
  memset(hx, 0, sizeof(hx));
  memset(hy, 0, sizeof(hy));
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) {
      cin >> a[i][j];
    }
  }
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) {
      cin >> b[i][j];
    }
  }
  for (long long i = 1; i < n; i++) {
    for (long long j = 1; j < m; j++) {
      if (a[i][j] != b[i][j]) {
        hx[i]++;
        hy[j]++;
        c++;
        hx[i] %= 2;
        hy[j] %= 2;
        c %= 2;
      }
    }
  }
  if ((c && a[0][0] == b[0][0]) || (!c && a[0][0] != b[0][0])) {
    cout << "No";
    return 0;
  }
  for (long long i = 1; i < n; i++) {
    if ((hx[i] && a[i][0] == b[i][0]) || (!hx[i] && a[i][0] != b[i][0])) {
      cout << "No";
      return 0;
    }
  }
  for (long long i = 1; i < m; i++) {
    if ((hy[i] && a[0][i] == b[0][i]) || (!hy[i] && a[0][i] != b[0][i])) {
      cout << "No";
      return 0;
    }
  }
  cout << "Yes";
}
