#include <bits/stdc++.h>
using namespace std;
long long int power(long long int a, long long int b) {
  if (b == 0) return 1;
  long long int c = power(a, b >> 1);
  c = (c * c) % 1000000007;
  if (b & 1) return (c * a) % 1000000007;
  return c;
}
const int N = (int)1e5 + 5;
int cnt[1010], a[510][510], b;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  memset(cnt, 0, sizeof(cnt));
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> a[i][j];
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> b;
      if (b != a[i][j]) {
        cnt[i]++;
        cnt[j + n]++;
      }
    }
  }
  bool ch = true;
  for (int i = 1; i < 1010; i++) {
    ch &= (cnt[i] % 2 == 0);
  }
  if (ch)
    cout << "Yes";
  else
    cout << "No";
}
