#include <bits/stdc++.h>
using namespace std;
const long long INF = 0x3f3f3f3f3f3f3f3fll;
const int inf = 0x3f3f3f3f;
const int maxn = 500 + 10;
const int maxm = 3000000 + 10;
const int mod = 1000000000;
int a[maxn][maxn], b[maxn][maxn];
int n, m;
void out() {
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      printf("%d ", a[i][j]);
    }
    printf("\n");
  }
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) cin >> a[i][j];
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) cin >> b[i][j];
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      a[i][j] ^= b[i][j];
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (a[i][j]) {
        int k, f1 = 1;
        int l, f2 = 1;
        for (k = i + 1; k <= n && f1; k++) {
          if (a[k][j]) {
            f1 = 0;
            break;
          }
        }
        for (l = j + 1; l <= m && f2; l++) {
          if (a[i][l]) {
            f2 = 0;
            break;
          }
        }
        if (!f1 && !f2) {
          a[i][j] ^= 1;
          a[i][l] ^= 1;
          a[k][j] ^= 1;
          a[k][l] ^= 1;
        }
      }
    }
  }
  int ans = 1;
  for (int i = 1; i <= n && ans; i++) {
    for (int j = 1; j <= m && ans; j++) {
      if (a[i][j]) {
        ans = 0;
        break;
      }
    }
  }
  if (ans) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}
