#include <bits/stdc++.h>
using namespace std;
long long power(long long a, long long b);
long long a[502][502], b[502][502];
long long n, m;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long t = 1, i;
  while (t--) {
    cin >> n >> m;
    for (long long i = 1; i <= n; i++) {
      for (long long j = 1; j <= m; j++) cin >> a[i][j];
    }
    for (long long i = 1; i <= n; i++) {
      for (long long j = 1; j <= m; j++) cin >> b[i][j];
    }
    long long flag = 0;
    for (long long i = 1; i <= n; i++) {
      long long val1 = 0;
      long long val2 = 0;
      for (long long j = 1; j <= m; j++) {
        val1 += a[i][j];
        val2 += b[i][j];
      }
      if (val1 % 2 != val2 % 2) {
        flag = 1;
        break;
      }
    }
    for (long long i = 1; i <= m; i++) {
      long long val1 = 0;
      long long val2 = 0;
      for (long long j = 1; j <= n; j++) {
        val1 += a[j][i];
        val2 += b[j][i];
      }
      if (val1 % 2 != val2 % 2) {
        flag = 1;
        break;
      }
    }
    if (flag)
      cout << "No"
           << "\n";
    else
      cout << "Yes"
           << "\n";
  }
  return 0;
}
long long power(long long a, long long b) {
  long long res = 1;
  while (b) {
    if (b % 2)
      b--, res = (res % 1000000007 * a % 1000000007);
    else
      b = b / 2, a = (a % 1000000007 * a % 1000000007) % 1000000007;
  }
  return res;
}
