#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL), cout.tie(NULL);
  long long int n, m;
  cin >> n >> m;
  long long 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];
  for (int i = 0; i < n - 1; i++)
    for (int j = 0; j < m - 1; j++) {
      if (b[i][j] != a[i][j])
        b[i][j] = !b[i][j], b[i + 1][j] = !b[i + 1][j],
        b[i + 1][j + 1] = !b[i + 1][j + 1], b[i][j + 1] = !b[i][j + 1];
    }
  for (int i = 0; i < n; i++)
    if (b[i][m - 1] != a[i][m - 1]) {
      cout << "No";
      return 0;
    }
  for (int i = 0; i < m; i++)
    if (b[n - 1][i] != a[n - 1][i]) {
      cout << "No";
      return 0;
    }
  cout << "Yes";
}
