#include <bits/stdc++.h>
using namespace std;
int a[505][505], b[505][505], c[505][505];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      scanf("%d", &a[i][j]);
    }
  }
  memset(c, 0, sizeof(c));
  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]) c[i][j] = 1;
    }
  }
  int cnt, x;
  for (int i = 1; i <= m; i++) {
    for (int j = i + 1; j <= m; j++) {
      cnt = 0;
      for (int k = 1; k <= n; k++) {
        if (!cnt && c[k][i] && c[k][j]) {
          cnt = 1;
          x = k;
        } else if (cnt && c[k][i]) {
          c[x][i] = c[x][j] = 0;
          c[k][i] = 0;
          c[k][j] = !c[k][j];
          cnt = 0;
        }
      }
    }
  }
  bool fg = false;
  for (int i = 1; i <= n; i++) {
    if (fg) break;
    for (int j = 1; j <= m; j++) {
      if (c[i][j]) {
        fg = true;
        break;
      }
    }
  }
  if (fg)
    printf("No");
  else
    printf("Yes");
  return 0;
}
