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