#include <bits/stdc++.h>
const long long mod = 490019;
void fail() {
  std::cout << "No\n";
  exit(0);
}
using namespace std;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n, m;
  cin >> n >> m;
  long long pre[2][n + m + 2][2];
  memset(pre, 0, sizeof(pre));
  long long a[n + 1][m + 1], b[n + 1][m + 1];
  for (long long i = 1; i <= n; i++)
    for (long long j = 1; j <= m; j++) {
      cin >> a[i][j];
      pre[0][i + j][a[i][j]]++;
    }
  for (long long i = 1; i <= n; i++)
    for (long long j = 1; j <= m; j++) {
      cin >> b[i][j];
      pre[1][i + j][b[i][j]]++;
    }
  for (long long i = 1; i <= n; i++) {
    long long chk = 0;
    for (long long j = 1; j <= m; j++) chk ^= (a[i][j] != b[i][j]);
    if (chk) fail();
  }
  for (long long i = 1; i <= m; i++) {
    long long chk = 0;
    for (long long j = 1; j <= n; j++) {
      chk ^= (a[j][i] != b[j][i]);
    }
    if (chk) fail();
  }
  cout << "Yes\n";
  return 0;
}
