#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const double eps = 1e-6;
const int mod = 1000000007;
int modpow(int x, int y, int md = mod) {
  if (y == 0) return 1;
  int ret = modpow(x, y >> 1, md);
  ret = (long long)ret * ret % md;
  if (y & 1) ret = (long long)ret * x % md;
  return ret;
}
int n, m;
int a[505][505];
int b[505][505];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) scanf("%d", &a[i][j]);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) scanf("%d", &b[i][j]);
  int suma = 0, sumb = 0;
  for (int i = 0; i < n; i++) {
    suma = 0;
    sumb = 0;
    for (int j = 0; j < m; j++) {
      suma ^= a[i][j];
      sumb ^= b[i][j];
    }
    if (suma != sumb) return puts("NO") & 0;
  }
  for (int j = 0; j < m; j++) {
    suma = 0;
    sumb = 0;
    for (int i = 0; i < n; i++) {
      suma ^= a[i][j];
      sumb ^= b[i][j];
    }
    if (suma != sumb) return puts("NO") & 0;
  }
  puts("Yes");
  return 0;
}
