#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e2 + 5;
int x, y, n, m, a[maxn][maxn];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) scanf("%d", &a[i][j]);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) scanf("%d", &x), a[i][j] ^= x;
  for (int i = 1; i <= n; i++) {
    queue<int> Q;
    for (int j = 1; j <= m; j++)
      if (a[i][j]) Q.push(j);
    if (Q.size() % 2) return !printf("No");
    while (!Q.empty()) {
      x = Q.front();
      Q.pop();
      y = Q.front();
      Q.pop();
      bool ok = false;
      for (int ii = i + 1; ii <= n && !ok; ii++)
        if (a[ii][x] || a[ii][y])
          a[ii][x] = !a[ii][x], a[ii][y] = !a[ii][y], ok = true;
      if (!ok) return !printf("No");
    }
  }
  return !printf("Yes");
}
