#include <bits/stdc++.h>

#define For(i, j, k) for(int i = j; i <= k; i++)

using namespace std;

const int N = 410;

int indeg[N], outdeg[N], fa[N];

int find(int x){
	return x == fa[x] ? x : fa[x] = find(fa[x]);
}

int n, H;

int main(){
	scanf("%d%d", &n, &H);

	For(i, 1, 2 * H) fa[i] = i;
	For(i, 1, n){
		int a, b, c, d;
		scanf("%d%d%d%d", &a, &b, &c, &d);
		int u = !c ? a : H + c, v = !d ? H + b : d;
		fa[find(u)] = find(v);
		++outdeg[u], ++indeg[v];
	}

	bool flag = true;
	For(i, 1, 2 * H) if(i == fa[i] && (indeg[i] || outdeg[i])){
		bool differ = false;
		For(j, 1, H) if(find(j) == i){
			if(outdeg[j] < indeg[j]) flag = false;
			if(outdeg[j] ^ indeg[j]) differ = true;
		}

		For(j, H + 1, 2 * H) if(find(j) == i){
			if(indeg[j] < outdeg[j]) flag = false;
			if(indeg[j] ^ outdeg[j]) differ = true;
		}

		if(!flag || !differ){
			flag = false;
			break;
		}
	}

	puts(flag ? "YES" : "NO");

	return 0;
}