#include <bits/stdc++.h>
using namespace std;
const int maxn = 500 + 5;
int A[maxn][maxn], B[maxn][maxn];
void change(int i, int j) {
  A[i][j] ^= 1;
  A[i + 1][j] ^= 1;
  A[i][j + 1] ^= 1;
  A[i + 1][j + 1] ^= 1;
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) scanf("%d", &A[i][j]);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) scanf("%d", &B[i][j]);
  for (int i = 1; i < n; i++) {
    for (int j = 1; j < m; j++)
      if (A[i][j] != B[i][j]) change(i, j);
  }
  bool ok = true;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) ok &= A[i][j] == B[i][j];
  if (ok)
    puts("Yes");
  else
    puts("No");
  return 0;
}
