#include <bits/stdc++.h>
using namespace std;
const double PI =
    3.14159265358979323846264338327950288419716939937510582097494459230781641;
const long long int M = 1e18;
const long long int MAXN = 100200;
void solve() {
  long long int n, m;
  cin >> n >> m;
  vector<vector<long long int> > a(n, vector<long long int>(m)),
      b(n, vector<long long int>(m));
  vector<long long int> x(n), y(n), r(m), s(m);
  for (long long int i = 0; i < n; i++) {
    long long int sum = 0;
    for (long long int j = 0; j < m; j++) {
      cin >> a[i][j];
      sum += a[i][j];
    }
    sum %= 2;
    x[i] = sum;
  }
  for (long long int i = 0; i < n; i++) {
    long long int sum = 0;
    for (long long int j = 0; j < m; j++) {
      cin >> b[i][j];
      sum += b[i][j];
    }
    sum %= 2;
    y[i] = sum;
  }
  for (long long int i = 0; i < m; i++) {
    long long int sum = 0;
    for (long long int j = 0; j < n; j++) {
      sum += a[j][i];
    }
    sum %= 2;
    r[i] = sum;
  }
  for (long long int i = 0; i < m; i++) {
    long long int sum = 0;
    for (long long int j = 0; j < n; j++) {
      sum += b[j][i];
    }
    sum %= 2;
    s[i] = sum;
  }
  if (x != y || r != s) {
    cout << "No";
  } else {
    cout << "Yes";
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long int test = 1;
  for (long long int t = 1; t < test + 1; t++) {
    solve();
    cout << "\n";
  }
  return 0;
}
