#define DEB
#include<bits/stdc++.h>
#define REP(i,m) for(int i=0;i<(m);++i)
#define REPN(i,m,in) for(int i=(in);i<(m);++i)
#define ALL(t) (t).begin(),(t).end()
#define CLR(a) memset((a),0,sizeof(a))
#define pb push_back
#define mp make_pair
#define fr first
#define sc second

using namespace std;


#ifdef DEB
#define dump(x)  cerr << #x << " = " << (x) << endl
#define prl cerr<<"called:"<< __LINE__<<endl
#define dumpR(x) cerr<<"\x1b[31m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
#define dumpY(x) cerr<<"\x1b[33m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
#define dumpG(x) cerr<<"\x1b[32m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
template<class T> void debug(T a,T b){ for(;a!=b;++a) cerr<<*a<<' ';cerr<<endl;}
#else
#define dump(x) ;
#define dumpR(x) ;
#define dumpY(x) ;
#define dumpG(x) ;
#define prl ;
template<class T> void debug(T a,T b){ ;}
#endif

template<class T> void chmin(T& a,const T& b) { if(a>b) a=b; }
template<class T> void chmax(T& a,const T& b) { if(a<b) a=b; }

typedef long long int lint;
typedef pair<int,int> pi;

namespace std{
  template<class S,class T>
  ostream &operator <<(ostream& out,const pair<S,T>& a){
    out<<'('<<a.fr<<','<<a.sc<<')';
    return out;
  }
}

const int INF=5e8;

//const int INF=5e8;
int n,H;
pair<pi,pi> ar[100005];
void ng(){
  puts("NO");
  exit(0);
}
vector<int> g[100005];
/*
vector<int> idL[205],idR[205];

bool vis[100005];


void dfs(int v,int p){
  dump(v);
  if(vis[v]) ng();
  vis[v]=1;
  for(auto to:g[v]){
    if(to==p) continue;
    dfs(to,v);
  }
}
*/

struct uf{

  static const int MAXN=405;
  int par[MAXN];
  int size[MAXN];
  void init(){
    memset(par,-1,sizeof(par));
    REP(i,MAXN) size[i]=1;
  }
  int root(int a){
    if(par[a]==-1) return a;
    return par[a]=root(par[a]);
  }
  void unite(int a,int b){
    a=root(a);b=root(b);
    if(a==b) return;
    if(size[a]<size[b]) swap(a,b);

    par[b]=a;
    size[a]+=size[b];
  }
  bool same(int a,int b){
    return root(a)==root(b);
  }
};

uf u;
int indeg[100005],outdeg[100005];

int dif[100005];
int mn[405],mx[405];
int main(){
  cin>>n>>H;
  ++H;
  u.init();
  REP(i,n){
    int a,b,c,d;scanf("%d%d%d%d",&a,&b,&c,&d);
    ar[i]={{a,b},{c,d}};
    //if(c==0) idL[a].pb(i);
    //if(d==0) idR[b].pb(i);

    int from,to;
    if(c==0) from=H+a;
    else from=c;

    if(d==0) to=b;
    else to=H+d;
    ++indeg[to];
    ++outdeg[from];
    g[from].pb(to);
    u.unite(from,to);
    if(from<H && to>=H) --dif[from];
    else if(from>=H && to<=H) ++dif[from];
  }
  REP(i,H){
    if(indeg[i]<outdeg[i]) ng();
    if(indeg[i+H]>outdeg[i+H]) ng();
  }
  REP(i,H*2) mn[i]=mx[i]=i;
  REP(i,H*2) if(u.root(i)!=i){
    dif[u.root(i)]+=dif[i];
    chmax(mx[u.root(i)],i);
    chmin(mn[u.root(i)],i);
  }
  REP(i,H*2) if(u.root(i)==i && indeg[i]+outdeg[i]>0){
    //assert(dif[i]>=0);
    if(dif[i]<=0) ng();
  }
  puts("YES");
/*
  REP(i,n){
    int a=ar[i].fr.fr,b=ar[i].fr.sc,c=ar[i].sc.fr,d=ar[i].sc.sc;
    if(c>0){
      if(idR[c].empty()) ng();
      int to=idR[c].back();
      idR[c].pop_back();
      g[i].pb(to);
      g[to].pb(i);
    }
    if(d>0){
      if(idL[d].empty()) ng();
      int to=idL[d].back();
      idL[d].pop_back();
      g[i].pb(to);
      g[to].pb(i);
    }
  }
  prl;
  REP(i,n) assert(g[i].size()<=2);
  REP(i,n) if(!vis[i]){
    dfs(i,-1);
  }
  */

 // puts("YES");
  return 0;
}





Measured memory_bytes: 4864