    #include<iostream>
    #include<cstring>
    #include<cstdio>
    using namespace std;
    inline int read()
    {
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
    return x*f;
    }
    int n,H,in[405],out[405],B[405],s[405],tote,size[405];
    inline int getfa(int x){return s[x]?s[x]=getfa(s[x]):x;}
    inline void Merge(int f,int t){if(getfa(f)!=getfa(t)) size[getfa(t)]+=size[getfa(f)],s[getfa(f)]=getfa(t);}
    int main()
    {
    n=read();H=read();
    for(int i=1;i<=n;++i)
    {
    int a=read(),b=read(),c=read(),d=read();
    int f=c?c+H:a,t=d?d:b+H;
    if(f==t) B[f]=1; else
    {
    ++out[f],++in[t];
    Merge(f,t);++size[getfa(f)];++tote;
    }
    // cout<<f<<" "<<t<<endl;
    }
    int S=0;
    for(int i=1;i<=H*2;++i)
    {
    // cout<<i<<" "<<in[i]<<" "<<out[i]<<endl;
    if(B[i]&&!in[i]&&!out[i]) return 0*puts("NO");
    if(i> H&&out[i]>in[i]) return 0*puts("NO");
    if(i<=H&&out[i]<in[i]) return 0*puts("NO");
    if(out[i]!=in[i])
    if(S) Merge(S,i);
    else S=i;
    }
    if(!S||size[getfa(S)]!=tote) return 0*puts("NO");
    puts("YES");
    return 0;
    }