#include <bits/stdc++.h>
using namespace std;
long long n, m;
long long a[555][555];
long long b[555][555];
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= m; j++) {
      cin >> a[i][j];
    }
  }
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= m; j++) {
      cin >> b[i][j];
    }
  }
  for (long long i = 1; i < n; i++) {
    for (long long j = 1; j <= m; j++) {
      if (a[i][j] != b[i][j]) {
        for (long long k = j + 1; k <= m; k++) {
          if (a[i][k] != b[i][k]) {
            a[i][j] ^= 1, a[i][k] ^= 1;
            a[i + 1][j] ^= 1, a[i + 1][k] ^= 1;
            j = k;
            break;
          }
        }
      }
    }
  }
  bool bad = 0;
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= m; j++) {
      if (a[i][j] != b[i][j]) {
        bad = 1;
      }
    }
  }
  cout << (bad ? "No" : "Yes") << "\n";
  return 0;
}
