#include<bits/stdc++.h>
#define L first
#define R second
#define pii pair<int,int>
using namespace std;
const int N=1e6+5;
int n,m,k;
int p[N];
int fl[N];
int x1[N],x2[N],y[N];
int fa[N];
vector<pii>s1[N],s2[N],s[N];
int find(int x){return fa[x]==x?x:fa[x]=find(fa[x]);}
bool merge(int x,int y){
x=find(x),y=find(y);
if(x==y)return 0;
else {fa[x]=y;return 1;}
}
void work(int id){
sort(s1[id].begin(),s1[id].end());
s2[id].push_back(s1[id][0]);
int now=0;
for(int i=1;i<(int)s1[id].size();i++){
if(s1[id][i].L>s2[id][now].R+1)
now++,s2[id].push_back(s1[id][i]);
else s2[id][now].R=s1[id][i].R;
}
if(s2[id][0].L!=1)s[id].push_back(pii(1,s2[id][0].L-1));
if(s2[id][now].R!=n)s[id].push_back(pii(s2[id][now].R+1,n));
for(int i=0;i<=now-1;i++){
int l=s2[id][i].R+1;
int r=s2[id][i+1].L-1;
if(l<=r)s[id].push_back(pii(l,r));
}
sort(s[id].begin(),s[id].end());
}
int ck(int l1,int r1,int l2,int r2){
int L=max(l1,l2);
int R=min(r1,r2);
return max(R-L+1,0);
}
int main(){
scanf("%d%d%d",&n,&m,&k);
for(int i=1;i<=k;i++){
scanf("%d%d%d",&x1[i],&x2[i],&y[i]);
p[i]=y[i];
}
if(m>=3e5+1||){puts("NO");return 0;}
sort(p+1,p+k+1);
int kk=unique(p+1,p+k+1)-p-1;
for(int i=1;i<=kk;i++)fl[p[i]]=i;
for(int i=1;i<=kk;i++)
if(p[i]-p[i-1]>=3){puts("NO");return 0;}
if((m+1)-p[kk]>=3){puts("NO");return 0;}
for(int i=1;i<=k;i++){
int id=fl[y[i]];
s1[id].push_back(pii(x1[i],x2[i]));
}
for(int i=1;i<=kk;i++)work(i);
for(int i=1;i<N;i++)fa[i]=i;
int sm=0;
s[0].push_back(pii(1,n));
for(int i=2;i<=m;i++){
int id1=fl[i-1],id2=fl[i];
int sz1=s[id1].size(),sz2=s[id2].size();
for(int t1=0;t1<sz1;t1++)
for(int t2=0;t2<sz2;t2++){
int l1=s[id1][t1].L,r1=s[id1][t1].R;
int l2=s[id2][t2].L,r2=s[id2][t2].R;
int num=ck(l1,r1,l2,r2);
if(num>=2){puts("NO");return 0;}
if(num==1){
int X=sm+t1+1,Y=sm+sz1+1+t2;
bool fl=merge(X,Y);
if(!fl){puts("NO");return 0;}
}
}
sm+=s[fl[i-1]].size();
}
puts("YES");
return 0;
}
/*
5 3 1
2 4 2
*/