#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void amin(T &x, const T &y) {
  if (y < x) x = y;
}
template <class T>
inline void amax(T &x, const T &y) {
  if (x < y) x = y;
}
template <class Iter>
void rprintf(const char *fmt, Iter begin, Iter end) {
  for (bool sp = 0; begin != end; ++begin) {
    if (sp)
      putchar(' ');
    else
      sp = true;
    printf(fmt, *begin);
  }
  putchar('\n');
}
int N, M;
int A[501][501];
int B[501][501];
bool check() {
  for (int i = 0, i_len = (N); i < i_len; ++i) {
    int x = 0;
    for (int j = 0, j_len = (M); j < j_len; ++j) x ^= A[i][j] ^ B[i][j];
    if (x & 1) return false;
  }
  for (int j = 0, j_len = (M); j < j_len; ++j) {
    int x = 0;
    for (int i = 0, i_len = (N); i < i_len; ++i) x ^= A[i][j] ^ B[i][j];
    if (x & 1) return false;
  }
  return true;
}
void MAIN() {
  scanf("%d%d", &N, &M);
  for (int i = 0, i_len = (N); i < i_len; ++i)
    for (int j = 0, j_len = (M); j < j_len; ++j) scanf("%d", A[i] + j);
  for (int i = 0, i_len = (N); i < i_len; ++i)
    for (int j = 0, j_len = (M); j < j_len; ++j) scanf("%d", B[i] + j);
  puts(check() ? "Yes" : "No");
}
int main() {
  int TC = 1;
  for (int tc = 0, tc_len = (TC); tc < tc_len; ++tc) MAIN();
  return 0;
}
