#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const long double PI = 4 * atan((long double)1);
long long power(long long a, long long n) {
  long long res = 1;
  while (n) {
    if (n % 2) res *= a;
    a *= a;
    n /= 2;
  }
  return res;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int n, m;
  cin >> n >> m;
  int a[n][m], b[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];
  }
  int diff[n][m], diffc[m];
  for (int i = (0); i < (n); ++i) {
    for (int j = (0); j < (m); ++j) {
      if (a[i][j] != b[i][j])
        diff[i][j] = 1;
      else
        diff[i][j] = 0;
    }
  }
  int e = 0;
  for (int i = (0); i < (n); ++i) {
    int cnt = 0;
    for (int j = (0); j < (m); ++j) {
      if (diff[i][j] == 1) cnt++;
    }
    if (cnt % 2 == 1) {
      e = 1;
      break;
    }
  }
  if (e == 1)
    cout << "No";
  else {
    for (int i = (0); i < (m); ++i) {
      int cnt = 0;
      for (int j = (0); j < (n); ++j) {
        if (diff[j][i] == 1) cnt++;
      }
      if (cnt % 2 == 1) {
        e = 1;
        break;
      }
    }
    if (e == 1)
      cout << "No";
    else
      cout << "Yes";
  }
  return 0;
}
