#include <bits/stdc++.h>
using namespace std;
const int maxn = 3010;
const long long Mod = 998244353;
int a[505][505];
int b[505][505];
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  int n, m;
  cin >> n >> m;
  int q1 = 0, q2 = 0, w1 = 0, w2 = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> a[i][j];
    }
  }
  int f = 0;
  for (int i = 1; i <= n; i++) {
    q1 = 0;
    q2 = 0;
    for (int j = 1; j <= m; j++) {
      cin >> b[i][j];
      if (b[i][j]) q2++;
      if (a[i][j]) q1++;
    }
    if ((q1 - q2) % 2 != 0) {
      f = 1;
      break;
    }
  }
  for (int i = 1; i <= m; i++) {
    q1 = 0;
    q2 = 0;
    for (int j = 1; j <= n; j++) {
      if (b[j][i]) q2++;
      if (a[j][i]) q1++;
    }
    if ((q1 - q2) % 2 != 0) {
      f = 1;
      break;
    }
  }
  if (f == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}
