#include <bits/stdc++.h>
using namespace std;
using vector_t = vector<int>;
class binary_matrix : vector<vector_t> {
  int even_rows() const {
    int n = size(), m = front().size();
    for (int i = 0; i < n; ++i) {
      int s = 0;
      for (int j = 0; j < m; ++j) s += at(i).at(j);
      if (s & 1) return 0;
    }
    return 1;
  }
  int even_columns() const {
    int n = size(), m = front().size();
    for (int j = 0; j < m; ++j) {
      int s = 0;
      for (int i = 0; i < n; ++i) s += at(i).at(j);
      if (s & 1) return 0;
    }
    return 1;
  }

 public:
  binary_matrix(int n, int m) {
    resize(n);
    for (auto& row : *this) {
      row.resize(m);
      for (auto& x : row) cin >> x;
    }
  }
  binary_matrix(const binary_matrix& a, const binary_matrix& b) {
    int n = a.size(), m = a.front().size();
    resize(n);
    for (int i = 0; i < n; ++i) {
      at(i).resize(m, 0);
      for (int j = 0; j < m; ++j)
        if (a[i][j] != b[i][j]) at(i).at(j) = 1;
    }
  }
  int valid() const { return even_rows() and even_columns(); }
};
int main() {
  ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  int n, m;
  cin >> n >> m;
  binary_matrix a(n, m), b(n, m);
  const string ans[] = {"No", "Yes"};
  cout << ans[binary_matrix(a, b).valid()];
}
