#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;
using vii = vector<ii>;
const ll MOD = 998244353;
const int INF = 1e9 + 9;
const int MAXN = 1000;
int n, m, k, a[MAXN][MAXN], b[MAXN][MAXN], good, bad;
bool feasible = true;
char s[MAXN], t[MAXN];
void met() { return; }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> a[i][j];
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> b[i][j];
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (a[i][j] == 1) good++;
      if (b[i][j] == 1) bad++;
    }
    if ((good - bad) % 2) feasible = false;
  }
  for (int j = 0; j < m; j++) {
    for (int i = 0; i < n; i++) {
      if (a[i][j] == 1) good++;
      if (b[i][j] == 1) bad++;
    }
    if ((good - bad) % 2) feasible = false;
  }
  if (feasible)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
