#include<bits/stdc++.h>
#define ll long long
using namespace std;
int n,h;
tuple<int,int,int,int> a[100010];int fa[100010];
int find(const int &x){return fa[x]==x?x:fa[x]=find(fa[x]);}
int ii[100010],oo[100010],mapp[100010];
void init(){
	for(int i=1;i<=n;i++){
		int f,t;
		if(f=get<2>(a[i])) f+=h;
		else f=get<0>(a[i]);
		if(t=get<3>(a[i]));
		else t=get<1>(a[i])+h;
		oo[f]++,ii[t]++;f=find(f),t=find(t);
		if(f^t) fa[f]=t;
	}
}
int main(){
	scanf("%d%d",&n,&h);
	for(int i=1;i<=1000;i++) fa[i]=i;
	int A,B,C,D;
	for(int i=1;i<=n;i++) scanf("%d%d%d%d",&A,&B,&C,&D),a[i]={A,B,C,D};
	bool fg=1;init();
	for(int i=1;i<=h;i++) if(ii[i]>oo[i]) fg=0;
	for(int i=h+1;i<=h+h;i++) if(ii[i]<oo[i]) fg=0;
	for(int i=1;i<=h+h;i++) if(ii[i]!=oo[i]||(ii[i]+oo[i]==0)) mapp[find(i)]++;
	for(int i=1;i<=h+h;i++) if(!mapp[i]&&i==fa[i]) fg=0;
	printf("%s\n",fg?"YES":"NO");
}
