#include<bits/stdc++.h>
#define rep(i, l, r) for(int i = (l), i##end = (r);i <= i##end;++i)
using std::cin; using std::cout;
const int maxn = 200200;
typedef long long ll;
const int mod = 998244353;
inline ll pow(ll a,int b,int ans = 1) {
	for(;b;b >>= 1,a = a * a % mod) if(b & 1)
		ans = ans * a % mod;
	return ans;
}
inline ll inverse(int x){ return pow(x, mod - 2); }
int n, h;
int fa[maxn], in[maxn], out[maxn], can[maxn];
inline int find(int x) {
	return fa[x] == x ? x : fa[x] = find(fa[x]);
}
int main() {
	std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n >> h;
	rep(i, 1, h + h) fa[i] = i;
	rep(i, 1, n) {
		int a, b, c, d;
		cin >> a >> b >> c >> d;
		int x0 = c ? c + h : a;
		int x1 = d ? d : b + h;
		fa[find(x0)] = find(x1);
		++ out[x0], ++ in[x1];
	}
	rep(i, 1, h) {
		if(out[i] < in[i] || out[i + h] > in[i + h]) {
			cout << "NO" << '\n';
			return 0;
		}
		if(out[i] != in[i]) can[find(i)] = 1;
		if(out[i + h] != in[i + h]) can[find(i + h)] = 1;
	}
	rep(i, 1, h + h) {
		if(in[i] && out[i] && !can[find(i)]) {
			cout << "NO" << '\n';
			return 0;
		}
	}
	cout << "YES" << '\n';
}
