#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

const long long INF = 1e18;
//const ll mod = 1000000007;
struct UnionFind {
    vector<int> par;
    vector<int> rank;
    vector<ll> Size;
    UnionFind(int n = 1) {
        init(n);
    }

    void init(int n = 1) {
        par.resize(n + 1); rank.resize(n + 1); Size.resize(n + 1);
        for (int i = 0; i <= n; ++i) par[i] = i, rank[i] = 0, Size[i] = 1;
    }

    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            return par[x] = r;
        }
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y);
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        Size[x] += Size[y];
        return true;
    }

    ll size(int x){
        return Size[root(x)];
    }
};

int N, H;
vector<int> vertex;
int degree[1000];
int v1[105000], v2[105000];
bool can[1000];
int main() {
    cin >> N >> H;
    cerr << N << " " << H << endl;
    UnionFind uni(3 * H);
    for(int i = 0; i < N; i++) {
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        cerr << a << " " << b << " " << c << " " << d << endl;
        if(c == 0) v1[i] = a;
        else v1[i] = H + c;
        if(d == 0) v2[i] = H + b;
        else v2[i] = d;
        degree[v1[i]]--;
        degree[v2[i]]++;
        uni.merge(v1[i], v2[i]);
        vertex.push_back(v1[i]);
        vertex.push_back(v2[i]);
        //cerr << v1[i] << " " << v2[i] << endl;
        if(v1[i] >= H + 1 and v2[i] <= H) {
            can[v1[i]] = true;
        }
    }
    sort(vertex.begin(), vertex.end());
    vertex.erase(unique(vertex.begin(), vertex.end()), vertex.end());
    map<int, vector<int>> mp;
    for(auto v : vertex) {
        /*
        if(!uni.issame(v, vertex[0])) {
            cout << "NO" << endl;
            return 0;
        }
        */
        mp[uni.root(v)].push_back(v);
    }
    cerr << "sz: " << mp.size() << endl;
    for(auto tmp : mp) {
        /*
        for(auto v : tmp.second) {
            cerr << v << " ";
        }
        cerr << endl;
        */
        vector<int> s, t;
        for(auto v : tmp.second) {
            if(degree[v] < 0) s.push_back(v);
            if(degree[v] > 0) t.push_back(v);
        }
        if(s.empty()) {
            assert(t.empty());
            cout << "NO" << endl;
            return 0;
            /*
            bool ok = false;
            for(auto v : tmp.second) {
                ok |= can[v];
            }
            if(!ok) {
                cout << "NO" << endl;
                assert(0);
                return 0;
            }
            */
        } else {
            //if(s <= H and t >= H + 1) cout << "YES" << endl;
            for(auto v : s) {
                if(v >= H + 1) {
                    cout << "NO" << endl;
                    //assert(0);
                    return 0;
                }
            }
            for(auto v : t) {
                if(v <= H) {
                    cout << "NO" << endl;
                    //assert(0);
                    return 0;
                }
            }
        }
    }
    cout << "YES" << endl;
    return 0;
    /*
    int s = -1, t = -1;
    for(auto v : vertex) {
        if(abs(degree[v]) >= 2) {
            cout << "NO" << endl;
            cerr << "DEGREE" << endl;
            return 0;
        }
        if(degree[v] == 1) {
            if(t != -1) {
                cout << "NO" << endl;
                cerr << "T" << endl;
                return 0;
            } else {
                t = v;
            }
        }
        if(degree[v] == -1) {
            if(s != -1) {
                cout << "NO" << endl;
                cerr << "S" << endl;
                cerr << s << " " << v << endl;
                return 0;
            } else {
                s = v;
            }
        }
    }
    if(s != -1) {
        assert(t != -1);
        if(s <= H and t >= H + 1) cout << "YES" << endl;
        else cout << "NO" << endl;
        return 0;
    }
    for(int i = 0; i < N; i++) {
        if(v1[i] >= H + 1 and v2[i] <= H) {
            cout << "YES" << endl;
            return 0;
        }
    }
    cout << "NO" << endl;
    */
    return 0;
}

Measured memory_bytes: 2044