#include <bits/stdc++.h>
const double PI = acos(-1.0);
using namespace std;
void fast_in_out() {
  std::ios_base::sync_with_stdio(NULL);
  cin.tie(NULL);
  cout.tie(NULL);
}
void pause() {}
int dx[] = {0, 0, -1, 1, -1, 1, -1, 1, 0};
int dy[] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
const int N = 3e5 + 20;
const long long mod = 1e9 + 7;
const long double eps = 1e-6;
int arr1[505][505];
int arr2[505][505];
int main() {
  fast_in_out();
  int n, m;
  int cnt1 = 0, cnt2 = 0;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) cin >> arr1[i][j];
  }
  bool ok = 1;
  for (int i = 0; i < n; i++) {
    int x = 0, y = 0;
    for (int j = 0; j < m; j++)
      cin >> arr2[i][j], x ^= arr1[i][j], y ^= arr2[i][j];
    if (x != y) ok = 0;
  }
  int sum1 = 0, sum2 = 0;
  for (int i = 0; i < m; i++) {
    int x = 0, y = 0;
    for (int j = 0; j < n; j++) x += arr1[j][i], y += arr2[j][i];
    sum1 += x;
    sum2 += y;
    if ((x & 1) != (y & 1)) ok = 0;
  }
  if (n < 2 || m < 2) {
    bool f = 1;
    for (int i = 0; i < n; i++)
      for (int j = 0; j < m; j++)
        if (arr1[i][j] != arr2[i][j]) f = 0;
    if (f)
      cout << "Yes\n";
    else
      cout << "No\n";
  } else {
    if (ok && ((cnt1 & 1) == (cnt2 & 1))) {
      cout << "Yes\n";
    } else
      cout << "No\n";
  }
  pause();
  return 0;
}
