#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
int m1[520][520];
int m2[520][520];
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", &m1[i][j]);
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      scanf("%d", &m2[i][j]);
    }
  }
  for (int i = 0; i < n; i++) {
    int x1 = 0, x2 = 0;
    for (int j = 0; j < m; j++) {
      x1 ^= m1[i][j];
      x2 ^= m2[i][j];
    }
    if (x1 ^ x2) {
      printf("No\n");
      return 0;
    }
  }
  for (int i = 0; i < m; i++) {
    int x1 = 0, x2 = 0;
    for (int j = 0; j < n; j++) {
      x1 ^= m1[j][i];
      x2 ^= m2[j][i];
    }
    if (x1 ^ x2) {
      printf("No\n");
      return 0;
    }
  }
  printf("Yes\n");
  return 0;
}
