#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 5, INF = 1e9 + 7;
long long a[505][505], b[505][505], c[505][505], i, j, m, n, p, q;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (i = 1; i <= n; i++)
    for (j = 1; j <= m; j++) cin >> a[i][j];
  for (i = 1; i <= n; i++)
    for (j = 1; j <= m; j++) {
      cin >> b[i][j];
      if (b[i][j] != a[i][j]) c[i][j] = 1;
    }
  for (i = 1; i <= n; i++) {
    long long k = 0;
    for (j = 1; j <= m; j++) {
      if (c[i][j] == 1) k++;
    }
    if (k % 2 == 1) {
      cout << "No" << endl;
      return 0;
    }
  }
  for (i = 1; i <= m; i++) {
    long long k = 0;
    for (j = 1; j <= n; j++) {
      if (c[j][i] == 1) k++;
    }
    if (k % 2 == 1) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}
