#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <iostream>
using namespace std;
const int MaxN = 505;
int n, h;
int in[MaxN], out[MaxN], ok[MaxN], fa[MaxN];
int Find(int x) { return x == fa[x] ? x : fa[x] = Find(fa[x]); }
void Init()
{
	scanf("%d%d", &n, &h);
	for (int i = 1; i <= (h << 1); ++i)
		fa[i] = i;
	for (int i = 1; i <= n; ++i)
	{
		int a, b, c, d, l, r;
		scanf("%d%d%d%d", &a, &b, &c, &d);
		l = (c == 0) ? h + a : c;
		r = (d == 0) ? b : h + d;
		++out[l];
		++in[r];
		if (Find(l) != Find(r))
			fa[Find(l)] = Find(r);
	}
}	
int Main()
{
	for (int i = 1; i <= h; ++i)
		if (out[i] > in[i])
			return puts("NO");
	for (int i = h + 1; i <= (h << 1); ++i)
		if (in[i] > out[i])
			return puts("NO");
	for (int i = 1; i <= (h << 1); ++i)
		if (in[i] != out[i])
			ok[Find(i)] = true;
	for (int i = 1; i <= (h << 1); ++i)
		if (Find(i) == i && !ok[i] && in[i] + out[i] != 0)
			return puts("NO");
	return puts("YES");
}
int main()
{
	Init();
	Main();
	return 0;
}