#include<bits/stdc++.h>
using namespace std;
const int N=4e2+7;

int n,h,in[N],out[N];

int f[2*N],hav[2*N];
inline int getf(int x){return f[x]?f[x]=getf(f[x]):x;}

int main(){
	scanf("%d%d",&n,&h);
	for(int i=1;i<=n;++i){
		int a,b,c,d;
		scanf("%d%d%d%d",&a,&b,&c,&d);
		int lv=c?c+h:a,rv=d?d:b+h;
		++out[lv]; ++in[rv];
		if(getf(lv)!=getf(rv)) f[getf(lv)]=rv;
	}
	for(int i=1;i<=h;++i) if(out[i]<in[i]) return puts("NO"),0;
	for(int i=h+1;i<=h+h;++i) if(out[i]>in[i]) return puts("NO"),0;
	for(int i=1;i<=h+h;++i) if(out[i]!=in[i]) hav[getf(i)]=1;
	for(int i=1;i<=h+h;++i) if(in[i]+out[i]&&getf(i)==i&&!hav[i]) return puts("NO"),0;
	return puts("YES"),0;
}