#include <bits/stdc++.h>
using namespace std;
const int maxn = 510;
int a[maxn][maxn], b[maxn][maxn];
int main() {
  int n, m;
  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]);
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (a[i][j] != b[i][j]) {
        if (i == n - 1 || j == m - 1) {
          printf("No\n");
          return 0;
        }
        b[i][j] ^= 1;
        b[i][j + 1] ^= 1;
        b[i + 1][j] ^= 1;
        b[i + 1][j + 1] ^= 1;
      }
    }
  }
  printf("Yes\n");
  return 0;
}
