#include <bits/stdc++.h>
using namespace std;
const int N = 505;
int a[N][N], b[N][N];
int n, m;
bool check() {
  for (int i = 1; i <= n; i++) {
    int cnt = 0;
    for (int j = 1; j <= m; j++)
      if (a[i][j]) ++cnt;
    if (cnt & 1) return 0;
  }
  for (int j = 1; j <= m; j++) {
    int cnt = 0;
    for (int i = 1; i <= n; i++)
      if (a[i][j]) ++cnt;
    if (cnt & 1) return 0;
  }
  return 1;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) scanf("%d", &b[i][j]);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      scanf("%d", &a[i][j]);
      a[i][j] = a[i][j] ^ b[i][j];
    }
  if (check())
    printf("Yes\n");
  else
    printf("No\n");
  return 0;
}
