#include <bits/stdc++.h>
using namespace std;
int A[510][510], B[510][510], M[510][510];
int main() {
  int n, m;
  while (scanf("%d%d", &n, &m) > 0) {
    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]);
        M[i][j] = A[i][j] ^ B[i][j];
      }
    }
    bool flag = true;
    for (int i = 0; i < n and flag; i++) {
      int x = 0;
      for (int j = 0; j < m; j++) {
        x ^= M[i][j];
      }
      if (x) flag = false;
    }
    for (int j = 0; j < m and flag; j++) {
      int x = 0;
      for (int i = 0; i < n; i++) {
        x ^= M[i][j];
      }
      if (x) flag = false;
    }
    printf("%s\n", flag ? "Yes" : "No");
  }
}
