#include <bits/stdc++.h>
using namespace std;
const int maxn = 600;
int a[maxn][maxn];
int b[maxn][maxn];
int col[maxn];
int row[maxn];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) cin >> a[i][j];
  }
  memset(col, 0, sizeof(col));
  memset(row, 0, sizeof(row));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> b[i][j];
      if (a[i][j] != b[i][j]) {
        row[i]++;
        col[j]++;
      }
    }
  }
  int flag = 0;
  for (int i = 0; i < n; i++) {
    if (row[i] & 1) flag = 1;
  }
  for (int i = 0; i < m; i++) {
    if (col[i] & 1) flag = 1;
  }
  if (flag)
    cout << "No" << endl;
  else
    cout << "Yes" << endl;
  return 0;
}
