#include <cstdio>

const int maxn = 410;

int n, m;
int in[maxn], out[maxn], par[maxn];
bool f[maxn];

int F(int u) {
	return par[u] == u ? u : par[u] = F(par[u]);
}

int main() {
	scanf("%d%d", &m, &n);
	for (int i = 1; i <= n + n; ++i) {
		par[i] = i;
	}
	for (int i = 1; i <= m; ++i) {
		int a, b, c, d, x, y;
		scanf("%d%d%d%d", &a, &b, &c, &d);
		x = c == 0 ? a : c + n;
		y = d == 0 ? b + n : d;
		par[F(x)] = F(y);
		++in[y];
		++out[x];
	}
	for (int i = 1; i <= n; ++i) {
		if(out[i] < in[i]) {
			return !puts("NO");
		}
		if(in[i] < out[i]) {
			f[F(i)] = 1;
		}
	}
	for (int i = 1; i <= n; ++i) {
		if(out[n + i] > in[n + i]) {
			return !puts("NO");
		}
	}
	for (int i = 1; i <= n + n; ++i) {
		if(F(i) == i && in[i] + out[i] && !f[i]) {
			return !puts("NO");
		}
	}
	return !puts("YES");
}