#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
using namespace std;
namespace io
{
	const int N=1<<20;
	char buf[N],*t1=buf,*t2=buf;
	#ifdef cjy
	#define getc() getchar()
	#else
	#define getc() t1==t2&&(t2=(t1=buf)+fread(buf,1,N,stdin),t1==t2)?EOF:*t1++
	#endif
	inline int read()
	{
		static int an,f;an=0,f=1;
		static char ch;ch=getc();
		while(ch<48||ch>57)ch=='-'?f=-1:0,ch=getc();
		while(ch>=48&&ch<=57)an=(an<<3)+(an<<1)+(ch^48),ch=getc();
		return an*f;
	}
	char buff[N],*T=buff;
	void flush(){fwrite(buff,1,T-buff,stdout);T=buff;}
	inline void putc(char ch){if(T==buff+N)flush();*T++=ch;}
	template<typename o>
	inline void print(o x)
	{
		if(x<0)putc('-'),x=-x;
		if(!x)return putc('0'),void();
		static int st[20],tp;
		while(x)st[++tp]=x%10,x/=10;
		while(tp)putc(st[tp]^48),--tp;
	}
}
using io::read;
using io::putc;
using io::flush;
using io::print;
struct edge
{
	int nxt,to;
}e[100010];
int n,h,head[500],num,dg[500];
inline void add(int from,int to){e[++num]=edge{head[from],to};head[from]=num;++dg[from],--dg[to];}
bool vis[500];
int main()
{
	n=read(),h=read();
	for(int i=1,a,b,c,d,x,y;i<=n;++i)
	{
		a=read(),b=read(),c=read(),d=read();
		if(c==0)x=a;
		else x=c+h;
		if(d==0)y=b+h;
		else y=d;
		add(x,y);
	}
	for(int i=1;i<=h;++i)if(dg[i]<0)return printf("NO"),0;
	for(int i=h+1;i<=2*h;++i)if(dg[i]>0)return printf("NO"),0;
	queue<int>q;
	for(int i=1;i<=h;++i)if(dg[i]>0)q.push(i);
	int cnt=0;
	while(!q.empty())
	{
		int x=q.front();q.pop();
	//	printf("%d\n",x);
		if(vis[x])continue;
		vis[x]=1;
		for(int i=head[x],y;i;i=e[i].nxt)y=e[i].to,++cnt,q.push(y);
	}
	if(cnt==n)printf("YES");
	else printf("NO");
	flush();
	return 0;
}