#include <bits/stdc++.h>
using namespace std;
const long long LINF = (long long)1e18 + 47;
const int INF = 1e9 + 47;
const int MOD = 998244353;
const int modulo = 1e8;
const int nax = 3 * (int)1e5 + 10;
const double EPS = 1e-9;
const double PI = acos(-1.0);
int a[510][510];
int b[510][510];
int col_a[510];
int row_a[510];
int col_b[510];
int row_b[510];
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  ;
  int n, m;
  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];
    }
  bool ok = true;
  for (int i = (0); i < (n); i++) {
    for (int j = (0); j < (m); j++) {
      col_a[i] += a[i][j];
      col_b[i] += b[i][j];
    }
    if (col_a[i] % 2 != col_b[i] % 2) ok = false;
  }
  for (int j = (0); j < (m); j++) {
    for (int i = (0); i < (n); i++) {
      row_a[j] += a[i][j];
      row_b[j] += b[i][j];
    }
    if (row_a[j] % 2 != row_b[j] % 2) ok = false;
  }
  if (ok)
    cout << "Yes\n";
  else
    cout << "No\n";
}
