#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int m, n;
  cin >> m >> n;
  int A[m][n];
  int B[m][n];
  int ans[m][n];
  int column[m];
  int row[n];
  for (long long int i = 0; i <= m - 1; i++) {
    for (long long int j = 0; j <= n - 1; j++) cin >> A[i][j];
  }
  for (long long int i = 0; i <= m - 1; i++) {
    for (long long int j = 0; j <= n - 1; j++) cin >> B[i][j];
  }
  for (long long int i = 0; i <= m - 1; i++) {
    for (long long int j = 0; j <= n - 1; j++) {
      if (A[i][j] == B[i][j])
        ans[i][j] = 0;
      else
        ans[i][j] = 1;
    }
  }
  for (long long int i = 0; i <= m - 1; i++) {
    int temp = 0;
    for (long long int j = 0; j <= n - 1; j++) temp += ans[i][j];
    column[i] = temp;
  }
  for (long long int j = 0; j <= n - 1; j++) {
    int temp = 0;
    for (long long int i = 0; i <= m - 1; i++) temp += ans[i][j];
    row[j] = temp;
  }
  int mis = 0;
  for (long long int i = 0; i <= m - 1; i++) mis += column[i];
  if (mis % 2 != 0) {
    cout << "No";
    return 0;
  } else {
    int flag = 0;
    for (long long int i = 0; i <= m - 1; i++) {
      if (column[i] % 2 != 0) {
        cout << "No";
        return 0;
      }
    }
    for (long long int i = 0; i <= n - 1; i++) {
      if (row[i] % 2 != 0) {
        cout << "No";
        return 0;
      }
    }
  }
  cout << "Yes";
  return 0;
}
