#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
  if (a == 0)
    return b;
  else
    return gcd(b % a, a);
}
long long int power(long long int a, long long int b, long long int m) {
  long long int ans = 1;
  while (b) {
    if (b & 1) ans = (ans * a) % m;
    b /= 2;
    a = (a * a) % m;
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int n, m;
  cin >> n >> m;
  long long int a[505][505], b[505][505];
  long long int row[505] = {0}, col[505] = {0};
  long long int c = 0;
  for (long long int i = 1; i < n + 1; i++)
    for (long long int j = 1; j < m + 1; j++) cin >> a[i][j];
  for (long long int i = 1; i < n + 1; i++)
    for (long long int j = 1; j < m + 1; j++) cin >> b[i][j];
  for (long long int i = 1; i < n + 1; i++) {
    for (long long int j = 1; j < m + 1; j++) {
      if (a[i][j] != b[i][j]) {
        c++;
        row[i]++;
        col[j]++;
      }
    }
  }
  if (c % 2) {
    cout << "No" << endl;
    return 0;
  }
  for (long long int i = 1; i < n + 1; i++) {
    if (row[i] % 2) {
      cout << "No" << endl;
      return 0;
    }
  }
  for (long long int i = 1; i < m + 1; i++) {
    if (col[i] % 2) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}
