#include <bits/stdc++.h>
using namespace std;
int mat_a[505][505];
int mat_b[505][505];
int row_a[505];
int column_a[505];
int row_b[505];
int column_b[505];
int n, m;
int main() {
  scanf("%d%d", &n, &m);
  int count_a = 0;
  int count_b = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      scanf("%d", &mat_a[i][j]);
      count_a += mat_a[i][j];
    }
    row_a[i] = (count_a & 1);
    count_a = 0;
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      scanf("%d", &mat_b[i][j]);
      count_b += mat_b[i][j];
    }
    row_b[i] = (count_b & 1);
    count_b = 0;
  }
  count_a = 0, count_b = 0;
  for (int j = 1; j <= m; j++) {
    for (int i = 1; i <= n; i++) {
      count_a += mat_a[i][j];
      count_b += mat_b[i][j];
    }
    column_a[j] = (count_a & 1);
    column_b[j] = (count_b & 1);
    count_a = 0, count_b = 0;
  }
  int flag = 0;
  for (int i = 1; i <= n; i++) {
    if (row_a[i] != row_b[i]) {
      flag = 1;
      break;
    }
  }
  if (!flag) {
    for (int j = 1; j <= m; j++) {
      if (column_a[j] != column_b[j]) {
        flag = 1;
        break;
      }
    }
    if (flag)
      puts("No");
    else
      puts("Yes");
  } else
    puts("No");
}
