#include <bits/stdc++.h>
using namespace std;
const int N = 505;
int a[N][N], b[N][N];
int row[N], col[N];
int rrow[N], ccol[N];
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", a[i] + j);
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      scanf("%d", b[i] + j);
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (a[i][j] ^ b[i][j]) {
        row[i]++;
        col[j]++;
      }
    }
  }
  for (int i = 0; i < n; i++) {
    if (row[i] & 1) {
      puts("No");
      return 0;
    }
  }
  for (int i = 0; i < m; i++) {
    if (col[i] & 1) {
      puts("No");
      return 0;
    }
  }
  puts("Yes");
  return 0;
}
