#include <bits/stdc++.h>
using namespace std;
const int N = 577, INF = 1e9, mod = 1e9 + 7;
int n, m;
long long h;
int a[N][N], b[N][N];
int ans;
int main() {
  cin >> 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", &b[i][j]);
      if (b[i][j] != a[i][j]) {
        b[1][1] = !b[1][1];
        b[i][1] = !b[i][1];
        b[1][j] = !b[1][j];
        b[i][j] = !b[i][j];
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (b[i][j] != a[i][j]) {
        printf("No\n");
        return 0;
      }
    }
  }
  printf("Yes\n");
  return 0;
}
