#include <bits/stdc++.h>
using namespace std;
const int maxn = 500 + 10;
const int inf = 0x3f3f3f3f;
const long long mod = 1000000009;
const double epx = 1e-6;
const double pi = acos(-1.0);
int a[maxn][maxn], b[maxn][maxn];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) cin >> a[i][j];
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) cin >> b[i][j];
  int flag = 0;
  for (int i = 0; i < n; i++) {
    int sum = 0;
    for (int j = 0; j < m; j++) {
      if (a[i][j] != b[i][j]) sum++;
    }
    if (sum % 2) flag = 1;
  }
  for (int j = 0; j < m; j++) {
    int sum = 0;
    for (int i = 0; i < n; i++) {
      if (a[i][j] != b[i][j]) sum++;
    }
    if (sum % 2) flag = 1;
  }
  if (flag)
    cout << "No" << endl;
  else
    cout << "Yes" << endl;
}
