#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define int ll
typedef long double ld;
typedef vector<int> vi;
#define vec vector
#define pii pair<int, int>

#define rep(i, a, b) for(int i = a; i < b; i++)
#define all(x) begin(x), end(x)
#define sz(x) (int)x.size()
#define setmin(x, y) x = min(x, y)
#define setmax(x, y) x = max(x, y)
#define ff first
#define ss second


signed main() {
    int n, m; cin >> n >> m;
    vec<vec<int>> rows(n + 1, vec<int>(m)), cols(n, vec<int>(m + 1));
    rep(i, 0, n) {
        rep(j, 0, m) cin >> rows[i][j];
        rep(j, 0, m + 1) cin >> cols[i][j];
    }
    rep(i, 0, m) cin >> rows[n][i];

    int tmp;
    rep(i, 0, n) {
        rep(j, 0, m) { cin >> tmp; rows[i][j] ^= tmp; }
        rep(j, 0, m + 1) { cin >> tmp; cols[i][j] ^= tmp; }
    }
    rep(i, 0, m) { cin >> tmp; rows[n][i] ^= tmp; }

    rep(i, 0, n) {
        rep(j, 0, m) {
            if(rows[i][j]) {
                rows[i][j] = 0;
                rows[i + 1][j] ^= 1;
                cols[i][j] ^= 1;
                cols[i][j + 1] ^= 1;
            }
        }
    }
    bool lstr = rows[n][0];
    rep(i, 0, m) {
        if(rows[n][i] != lstr) {
            cout << "No\n";
            return 0;
        }
    }

    rep(i, 0, n) {
        if(cols[i][0]){
            cols[i][m] ^= 1;
            cols[i][0] = 0;
        }
    }

    rep(j, 0, m + 1) {
        bool lstc = cols[0][j];
        rep(i, 0, n) {
            if(cols[i][j] != lstc) {
                cout << "No\n";
                return 0;
            }
        }
    }
    cout << "Yes\n";
}