#include <bits/stdc++.h>

void bye() { std::cout << "NO" << std::endl; exit(0); }
int ind[410], oud[410], fa[410], idx;
int p[210][2], hav[410];
int n, H;
int find(int x) { return x == fa[x] ? x : fa[x] = find(fa[x]); }
int newnode() { ++idx; fa[idx] = idx; return idx; }
int get(int x, int b) { return p[x][b] ? p[x][b] : p[x][b] = newnode(); }
void adde(int b, int e) { ++ind[e], ++oud[b]; fa[find(b)] = find(e); }
int main() {
	std::ios_base::sync_with_stdio(false), std::cin.tie(0);
	std::cin >> n >> H;
	for (int i = 1; i <= n; ++i) {
		int a, b, c, d;
		std::cin >> a >> b >> c >> d;
		adde(c ? get(c, 1) : get(a, 0), d ? get(d, 0) : get(b, 1));
	}
	for (int i = 1; i <= H; ++i) {
		if (int t = p[i][0]) {
			if (ind[t] > oud[t]) bye(); hav[find(t)] |= ind[t] != oud[t];
		}
		if (int t = p[i][1]) {
			if (ind[t] < oud[t]) bye(); hav[find(t)] |= ind[t] != oud[t];
		}
	}
	for (int i = 1; i <= idx; ++i) if (fa[i] == i && !hav[i]) bye();
	std::cout << "YES" << std::endl;
	return 0;
}
