#include <bits/stdc++.h>
using namespace std;
int m1[503][503], m2[503][503], col[503];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < 503; i++) {
    col[i] = 0;
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> m1[i][j];
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> m2[i][j];
      if (m1[i][j] != m2[i][j]) {
        col[j]++;
      }
    }
  }
  for (int i = 0; i < m; i++) {
    if (col[i] % 2 == 1) {
      cout << "No\n";
      return 0;
    }
  }
  for (int i = 0; i < n; i++) {
    int cnt = 0, x, y;
    for (int j = 0; j < m; j++) {
      if (m1[i][j] != m2[i][j]) {
        cnt++;
        if (cnt == 1) {
          x = j;
        } else {
          y = j;
        }
      }
      if (cnt == 2) {
        cnt = 0;
      }
    }
    if (cnt == 1) {
      cout << "No\n";
      return 0;
    }
  }
  cout << "Yes\n";
  return 0;
}
