#include <bits/stdc++.h>
using namespace std;
const long long int INF = 1e18;
const long long int mxn = 1e5 + 1;
const string fuck = "fuck";
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));
  for (long long int i = 0; i < n; i++) {
    for (long long int j = 0; j < m; j++) {
      cin >> a[i][j];
    }
  }
  for (long long int i = 0; i < n; i++) {
    for (long long int j = 0; j < m; j++) {
      cin >> b[i][j];
    }
  }
  for (long long int i = 0; i < n; i++) {
    for (long long int j = 0; j < m; j++) {
      if (a[i][j] != b[i][j]) {
        a[i][j] ^= 1;
        a[0][j] ^= 1;
        a[i][0] ^= 1;
        a[0][0] ^= 1;
      }
    }
  }
  for (long long int i = 0; i < n; i++) {
    for (long long int j = 0; j < m; j++) {
      if (a[i][j] != b[i][j]) {
        cout << "No";
        return;
      }
    }
  }
  cout << "Yes";
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  long long int cse = 1;
  while (cse--) {
    solve();
    cout << endl;
  }
}
