#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
using namespace std;
const long long int MAX = -1000000000000000000;
const long long int MIN = 1000000000000000000;
const long long int inf = 1000000000;
const long long int KOK = 100000;
const long long int LOG = 30;
const long long int li = 100005;
const long long int mod = 1000000007;
long long int n, m, cev, b[1005][1005], a[1005][1005], k, cev1;
string s;
vector<long long int> v;
inline long long int solve() {
  scanf("%lld %lld", &n, &m);
  for (long long int i = 1; i <= n; i++) {
    for (long long int j = 1; j <= m; j++) scanf("%lld", &a[i][j]);
  }
  for (long long int i = 1; i <= n; i++) {
    for (long long int j = 1; j <= m; j++) scanf("%lld", &b[i][j]);
  }
  for (long long int i = 1; i <= n; i++) {
    cev1 = 0;
    cev = 0;
    for (long long int j = 1; j <= m; j++) cev += a[i][j];
    for (long long int j = 1; j <= m; j++) cev1 += b[i][j];
    if (cev % 2 != cev1 % 2) {
      printf("No\n");
      return 0;
    }
  }
  for (long long int j = 1; j <= m; j++) {
    cev1 = 0;
    cev = 0;
    for (long long int i = 1; i <= n; i++) cev += a[i][j];
    for (long long int i = 1; i <= n; i++) cev1 += b[i][j];
    if (cev % 2 != cev1 % 2) {
      printf("No\n");
      return 0;
    }
  }
  printf("Yes\n");
  return 0;
}
int main(void) {
  solve();
  return 0;
}
