#include <bits/stdc++.h>
using namespace std;
int read() {
  char c = getchar();
  int d = 0, f = 1;
  for (; c < '0' || c > '9'; c = getchar())
    if (c == '-') f = -1;
  for (; c >= '0' && c <= '9'; d = d * 10 - 48 + c, c = getchar())
    ;
  return d * f;
}
int n, m, a[501][501], b[5001][501], c[501];
int main() {
  n = read(), m = read();
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j) a[i][j] = read();
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j) b[i][j] = read() ^ a[i][j];
  for (int i = 1; i <= n; ++i) {
    int c = 0;
    for (int j = 1; j <= m; ++j) c ^= b[i][j];
    if (c) {
      puts("No");
      return 0;
    }
  }
  for (int j = 1; j <= m; ++j) {
    int c = 0;
    for (int i = 1; i <= n; ++i) c ^= b[i][j];
    if (c) {
      puts("No");
      return 0;
    }
  }
  puts("Yes");
  return 0;
}
