#include <bits/stdc++.h>
using namespace std;
int N, M;
int A[505][505], B[505][505];
int ro[505], co[505];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N >> M;
  for (int i = 0; i <= N - 1; i++)
    for (int j = 0; j <= M - 1; j++) cin >> A[i][j];
  for (int i = 0; i <= N - 1; i++)
    for (int j = 0; j <= M - 1; j++) cin >> B[i][j];
  for (int i = 0; i <= N - 1; i++)
    for (int j = 0; j <= M - 1; j++) {
      ro[i] += (A[i][j] != B[i][j]);
      co[j] += (A[i][j] != B[i][j]);
    }
  bool first = 0;
  for (int i = 0; i <= N - 1; i++)
    if (ro[i] % 2) first = 1;
  for (int i = 0; i <= M - 1; i++)
    if (co[i] % 2) first = 1;
  cout << (first ? "No\n" : "Yes\n");
  return 0;
}
