#include <bits/stdc++.h>
using namespace std;
long long a[505][505], b[505][505];
vector<long long> v1, v2;
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n, m;
  cin >> n >> m;
  for (long long i = 0; i < n; i++)
    for (long long j = 0; j < m; j++) cin >> a[i][j];
  for (long long i = 0; i < n; i++)
    for (long long j = 0; j < m; j++) cin >> b[i][j];
  for (long long i = 0; i < m; i++) {
    long long temp = 0;
    for (long long j = 0; j < n; j++)
      if (a[j][i] != b[j][i]) temp++;
    v1.push_back(temp);
  }
  for (long long i = 0; i < v1.size(); i++)
    if (v1[i] % 2 == 1) {
      cout << "No";
      return 0;
    }
  long long temp = 0;
  for (long long i = 0; i < n; i++)
    for (long long j = 0; j < m; j++) temp++;
  for (long long i = 0; i < n; i++) {
    long long temp = 0;
    for (long long j = 0; j < m; j++)
      if (a[i][j] != b[i][j]) temp++;
    v2.push_back(temp);
  }
  for (long long i = 0; i < v2.size(); i++)
    if (v2[i] % 2 == 1) {
      cout << "No";
      return 0;
    }
  temp = 0;
  for (long long i = 0; i < n; i++)
    for (long long j = 0; j < m; j++) temp++;
  if (temp >= 0) cout << "Yes";
  return 0;
}
