#include <cstdio>
#include <vector>
using namespace std;

#define iter(i, n) for (int i = 1; i <= n; ++i)

#define PR 510

vector<int> e[PR];
bool invalid, vis[PR], start;
int sum, deg[PR], n, h;

void dfs(int x) {
	vis[x] = true;
	sum += deg[x];
	if (deg[x] != 0) {
		start = true;
		if ((deg[x] > 0) != (x <= h)) invalid = true;
	}
	for (int v : e[x]) if (!vis[v]) dfs(v);
}

int main() {
	scanf("%d%d", &n, &h);
	iter(i, 2 * h) vis[i] = true;
	iter(i, n) {
		int a, b, c, d;
		scanf("%d%d%d%d", &a, &b, &c, &d);
		int u = c == 0 ? a : c + h;
		int v = d == 0 ? b + h : d;
		e[u].push_back(v);
		e[v].push_back(u);
		//printf("%d->%d\n", u, v);
		++deg[u], --deg[v]; vis[u] = vis[v] = false;
	}

	//iter(i, 2 * h) printf("%d ", deg[i]);

	iter(i, 2 * h) if (!vis[i]) {
		start = false; dfs(i);
		if (sum != 0 || !start) invalid = true;
	}

	puts(invalid ? "NO" : "YES");
	return 0;
}
