#include <bits/stdc++.h>
using namespace std;
char buf[1 << 21], *p1 = buf, *p2 = buf;
template <class T>
void read(T &x) {
  x = 0;
  int c = getchar();
  int flag = 0;
  while (c < '0' || c > '9') flag |= (c == '-'), c = getchar();
  while (c >= '0' && c <= '9')
    x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
  if (flag) x = -x;
}
template <class T>
T _max(T a, T b) {
  return b < a ? a : b;
}
template <class T>
T _min(T a, T b) {
  return a < b ? a : b;
}
template <class T>
bool checkmax(T &a, T b) {
  return a < b ? a = b, 1 : 0;
}
template <class T>
bool checkmin(T &a, T b) {
  return b < a ? a = b, 1 : 0;
}
int n, m;
int a[505][505], b[505][505];
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][m] ^= 1;
        a[n][j] ^= 1, a[n][m] ^= 1;
      }
    }
  }
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j)
      if (a[i][j] != b[i][j]) {
        printf("No\n");
        return;
      }
  printf("Yes\n");
}
int main() {
  init();
  solve();
  return 0;
}
