#include <bits/stdc++.h>
using namespace std;
const int NUM = 2e5 + 5;
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << "\n";
  err(++it, args...);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int num_tests = 1;
  while (num_tests-- > 0) {
    int n, m;
    cin >> n >> m;
    int a[n][m], b[n][m];
    int cnta = 0, cntb = 0;
    for (long long int i = 0; i < n; i++)
      for (long long int j = 0; j < m; j++) {
        cin >> a[i][j];
        if (a[i][j]) cnta++;
      }
    for (long long int i = 0; i < n; i++)
      for (long long int j = 0; j < m; j++) {
        cin >> b[i][j];
        if (b[i][j]) cntb++;
      }
    if (cnta % 2 != cntb % 2) {
      cout << "No";
      return 0;
    }
    for (long long int i = 0; i < n; i++) {
      int cnt1 = 0, cnt2 = 0;
      for (long long int j = 0; j < m; j++) {
        if (a[i][j]) cnt1++;
        if (b[i][j]) cnt2++;
      }
      if (cnt1 % 2 != cnt2 % 2) {
        cout << "No";
        return 0;
      }
    }
    for (long long int i = 0; i < m; i++) {
      int cnt1 = 0, cnt2 = 0;
      for (long long int j = 0; j < n; j++) {
        if (a[j][i]) cnt1++;
        if (b[j][i]) cnt2++;
      }
      if (cnt1 % 2 != cnt2 % 2) {
        cout << "No";
        return 0;
      } else
        cnt1 = 0, cnt2 = 0;
    }
    cout << "Yes";
  }
}
