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