#include <bits/stdc++.h>
using namespace std;
template <class T>
void read(T &x) {
  x = 0;
  char c = getchar();
  while (c < '0' || c > '9') {
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = (x << 3) + (x << 1) + c - 48;
    c = getchar();
  }
}
template <class T>
void write(T x) {
  if (x < 10) {
    putchar('0' + x);
    return;
  } else {
    write(x / 10);
    write(x % 10);
  }
}
template <class T>
void writeln(T x) {
  write(x);
  putchar('\n');
}
const int N = 505;
int n, m;
int a[N][N], b[N][N];
void init() {
  read(n);
  read(m);
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      read(a[i][j]);
    }
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      read(b[i][j]);
    }
  }
}
void solve() {
  for (int i = 1; i < n; ++i) {
    for (int j = 1; j < m; ++j) {
      if (a[i][j] != b[i][j]) {
        a[i][j] ^= 1;
        a[i][j + 1] ^= 1;
        a[i + 1][j] ^= 1;
        a[i + 1][j + 1] ^= 1;
      }
    }
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      if (a[i][j] != b[i][j]) {
        puts("No");
        return;
      }
    }
  }
  puts("Yes");
}
int main() {
  init();
  solve();
  return 0;
}
