#include<iostream>
#include<algorithm>
#include<cmath>
#include<stdio.h>
using namespace std;
int n,m;
int fa[2000003],vis[2000003],D[2000003],C[2000003];
inline int find(int x){
	if(fa[x]==x){
		return fa[x];
	}else{
		return fa[x]=find(fa[x]);
	}
}
int main(){
	cin>>n>>m;
    for(int i=1;i<=1000;i++){
    	fa[i]=i;
	}
    for(int i=1;i<=n;i++){
        int x,y,a,b,c,d;
        cin>>a>>b>>c>>d;
        x=!c?a+500:-c+500;
        y=!d?-b+500:d+500;
        fa[find(x)]=find(y);
        D[x]++,D[y]--;
		vis[x]=1;
    }
    int flag=1;
    for(int i=1;i<500;i++){
    	if(D[i]>0){
			puts("NO");
    		return 0;
		}
	}
    for(int i=501;i<=1000;i++){
    	if(D[i]<0){
    		puts("NO");
    		return 0;
		}
	}
    for(int i=1;i<=1000;i++){
    	vis[find(i)]|=vis[i];
	}
    for(int i=1;i<=1000;i++){
		if(D[i]!=0){
			C[find(i)]=1;
		}
	}
    for(int i=1;i<=1000;i++){
    	if(fa[i]==i&&!C[i]&&vis[i]){
    		puts("NO");
    		return 0;
		}
	}
	cout<<"YES"<<endl;
    return 0;
}