#include <bits/stdc++.h>
using namespace std;
int n, m;
int a[510][510], b[510][510];
int main() {
  ios::sync_with_stdio(false);
  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++) {
      if (a[i][j] == b[i][j]) continue;
      a[i][j] ^= 1;
      a[i][1] ^= 1;
      a[1][j] ^= 1;
      a[1][1] ^= 1;
    }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      if (a[i][j] != b[i][j]) {
        cout << "No";
        return 0;
      }
  cout << "Yes";
  return 0;
}
