#include <bits/stdc++.h>
using namespace std;
const long long int MOD = 1000000007;
const long double PI = 2 * acos(0.0);
const vector<long long int> dx = {1, -1, 0, 0};
const vector<long long int> dy = {0, 0, 1, -1};
vector<long long int> ga(long long int n, bool oneIndexed = false) {
  vector<long long int> a;
  if (oneIndexed) a.push_back(0ll);
  for (long long int i = 0; i < n; i++) {
    long long int p;
    cin >> p;
    a.push_back(p);
  }
  return move(a);
}
vector<unsigned long long int> gau(unsigned long long int n,
                                   bool oneIndexed = false) {
  vector<unsigned long long int> a;
  if (oneIndexed) a.push_back(0llu);
  for (unsigned long long int i = 0; i < n; i++) {
    unsigned long long int p;
    cin >> p;
    a.push_back(p);
  }
  return move(a);
}
vector<string> gas(unsigned long long int n, bool oneIndexed = false) {
  vector<string> a;
  if (oneIndexed) a.push_back("");
  for (unsigned long long int i = 0; i < n; i++) {
    string p;
    cin >> p;
    a.push_back(p);
  }
  return move(a);
}
template <typename T, typename A>
void pa(vector<T, A> const &a, long long int begin = 0,
        long long int end = -1) {
  if (end == -1) end = a.size() - 1;
  for (long long int i = begin; i <= end; i++) {
    cout << a[i] << " ";
  }
  cout << "\n";
}
void yes() { cout << "Yes\n"; }
void no() { cout << "No\n"; }
void yesno(int f) {
  if (f)
    yes();
  else
    no();
}
void solve() {
  long long int n, m;
  cin >> n >> m;
  vector<vector<long long int>> a(n, vector<long long int>(m)),
      b(n, vector<long long int>(m));
  for (long long int i = 0; i < n; i++) {
    for (long long int j = 0; j < m; j++) {
      cin >> a[i][j];
    }
  }
  for (long long int i = 0; i < n; i++) {
    for (long long int j = 0; j < m; j++) {
      cin >> b[i][j];
    }
  }
  if (n == 1 && m == 1) {
    yesno(a[0][0] == b[0][0]);
    return;
  } else if (n == 1 && m == 2) {
    yesno(a[0][0] == b[0][0] && a[0][1] == b[0][1]);
    return;
  } else if (n == 2 && m == 1) {
    yesno(a[0][0] == b[0][0] && a[1][0] == b[1][0]);
    return;
  }
  for (long long int i = 0; i < n - 1; i++) {
    for (long long int j = 0; j < m - 1; j++) {
      if (a[i][j] != b[i][j]) {
        b[i][m - 1] = !b[i][m - 1];
        b[n - 1][j] = !b[n - 1][j];
        b[n - 1][m - 1] = !b[n - 1][m - 1];
      }
    }
  }
  for (long long int i = 0; i < n; i++) {
    if (a[i][m - 1] != b[i][m - 1]) {
      no();
      return;
    }
  }
  for (long long int i = 0; i < m; i++) {
    if (a[n - 1][i] != b[n - 1][i]) {
      no();
      return;
    }
  }
  yes();
}
int main(void) {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  solve();
  return 0;
}
