#include <bits/stdc++.h>
using namespace std;
long long read() {
  long long x = 0, f = 0;
  char ch = getchar();
  while (!isdigit(ch)) {
    f |= (ch == '-');
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return f ? -x : x;
}
void write(long long x) {
  if (x < 0) putchar('-'), x = -x;
  if (x >= 10) write(x / 10);
  putchar(x % 10 + '0');
}
long long n, m, a[560][560], b[560][560], hang[560], lie[560];
signed main() {
  n = read();
  m = read();
  for (long long i = 1; i <= n; i++)
    for (long long j = 1; j <= m; j++) a[i][j] = read();
  for (long long i = 1; i <= n; i++)
    for (long long j = 1; j <= m; j++) b[i][j] = read();
  for (long long i = 1; i <= n; i++)
    for (long long j = 1; j <= m; j++) {
      if (a[i][j] != b[i][j]) hang[i]++, lie[j]++;
    }
  long long flag = 1;
  for (long long i = 1; i <= n; i++)
    if (hang[i] % 2 == 1) {
      flag = 0;
      break;
    }
  for (long long j = 1; j <= m; j++)
    if (lie[j] % 2 == 1) {
      flag = 0;
      break;
    }
  if (flag)
    puts("Yes");
  else
    puts("No");
  return 0;
}
