#include <bits/stdc++.h>
int N, M, x;
int a1[503], b1[503], a2[503], b2[503];
int main() {
  scanf(" %d %d", &N, &M);
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < M; ++j) {
      scanf(" %d", &x);
      a1[i] ^= x;
      b1[j] ^= x;
    }
  }
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < M; ++j) {
      scanf(" %d", &x);
      a2[i] ^= x;
      b2[j] ^= x;
    }
  }
  for (int i = 0; i < N; ++i) {
    if (a1[i] != a2[i]) {
      printf("No\n");
      return 0;
    }
  }
  for (int i = 0; i < M; ++i) {
    if (b1[i] != b2[i]) {
      printf("No\n");
      return 0;
    }
  }
  printf("Yes\n");
  return 0;
}
