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