#include <bits/stdc++.h>
using namespace std;
int num[505][505];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      int x;
      scanf("%d", &x);
      num[i][j] ^= x;
    }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      int x;
      scanf("%d", &x);
      num[i][j] ^= x;
    }
  for (int i = 1; i < n; i++)
    for (int j = 1; j < m; j++)
      if (num[i][j]) {
        num[i][j] ^= 1;
        num[i][j + 1] ^= 1;
        num[i + 1][j] ^= 1;
        num[i + 1][j + 1] ^= 1;
      }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      if (num[i][j]) {
        puts("No");
        return 0;
      }
  puts("Yes");
  return 0;
}
