#include <bits/stdc++.h>
using namespace std;
const int maxn = 5E2 + 5;
bool A[maxn][maxn], B[maxn][maxn], C[maxn][maxn];
int main() {
  int n, m;
  while (cin >> 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];
    bool flag = 1;
    for (int i = 0; i < n; ++i) {
      int ans = 0;
      for (int j = 0; j < m; ++j) {
        C[i][j] = A[i][j] ^ B[i][j];
        ans += C[i][j];
      }
      if (ans & 1) flag = 0;
      cout << endl;
    }
    for (int j = 0; j < m; ++j) {
      int ans = 0;
      for (int i = 0; i < n; ++i) ans += C[i][j];
      if (ans & 1) flag = 0;
    }
    if (flag)
      cout << "Yes";
    else
      cout << "No";
    cout << endl;
  }
}
