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