#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

#define F first
#define S second

const int MAXN = 1e5 + 10;

int n, h, c1[MAXN], c0[MAXN];
bool vis[MAXN];
vector<int> adj[MAXN];
bool found = 0;

void dfs(int v){
	vis[v] = 1;
	if (c0[v] ^ c1[v]) found = 1;
	if ((v > h && c1[v] > c0[v]) || (v <= h && c0[v] > c1[v])){
		cout << "NO\n";
		exit(0);
	}
	for (int u:adj[v])
		if (!vis[u])
			dfs(u);
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n >> h;
	while (n--){
		int a, b, c, d; cin >> a >> b >> c >> d;
		int u = -1, v = -1;
		if (c == 0)
			u = a;
		else
			u = h+c;
		if (d)
			v = d;
		else
			v = h+b;
		adj[u].push_back(v);
		c1[u]++;
		adj[v].push_back(u);
		c0[v]++;
	}
	for (int i = 1; i <= h+h; i++)
		if (!vis[i] && adj[i].size()){
			found = 0;
			dfs(i);
			if (!found){
				cout << "NO\n";
				return 0;
			}
		}
	cout << "YES\n";
	return 0;
}
