#include <bits/stdc++.h>
using namespace std;
int n, m, rs[2][505], cs[2][505], tmp;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < 2; ++i)
    for (int j = 0; j < n; ++j)
      for (int k = 0; k < m; ++k) {
        scanf("%d", &tmp);
        rs[i][j] ^= tmp;
        cs[i][k] ^= tmp;
      }
  int flag = 1;
  for (int i = 0; i < n; ++i)
    if (rs[0][i] != rs[1][i]) {
      flag = 0;
      break;
    }
  if (flag) {
    for (int i = 0; i < m; ++i)
      if (cs[0][i] != cs[1][i]) {
        flag = 0;
        break;
      }
  }
  if (flag)
    printf("Yes\n");
  else
    printf("No\n");
  return 0;
}
