#include <bits/stdc++.h>
#define ll long long
#define For(i,a,b) for (int i=a;i<=b;i++)
#define Rep(i,a,b) for (int i=b;i>=a;i--)
#define N 2000500
using namespace std;
int n,m,fa[N],vis[N],D[N],C[N];
int gf(int x) {return fa[x]==x?x:fa[x]=gf(fa[x]);}
inline ll read()
{
    ll 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 main() 
{
    n = read(), m = read();
	For(i,1,1000)fa[i] = i;
    For(i,1,n)
	{
        int x, y,a,b,c,d;
        a = read(), b = read(), c = read(), d = read();
        x=!c?a:-c; x+=500;
        y=!d?-b:d; y+=500;
        fa[ gf(x) ] = gf(y);
        D[x]++, D[y]--, vis[x] = 1;
    }
    int flag = 1;
	For(i,1,499)D[i]>0 ? flag=0 :0;
	For(i,501,1000)D[i]<0 ? flag=0 :0;
	For(i,1,1000)vis[gf(i)] |= vis[i];
    For(i,1,1000) if (D[i]) C[gf(i)] = 1;
    For(i,1,1000) if (fa[i]==i && !C[i] && vis[i]) flag = 0;
    puts(flag?"YES":"NO");
    return 0;
}