#include using namespace std; using ll =long long; #define all(v) v.begin(),v.end() #define rep(i,a,b) for(int i=a;i=b;i--) ll INF=2e18; const ll MAX_N=1<<17; ll n; vector dat; void init(ll n_) { n=1; while (n (2*n-1,INF); } void update(ll k, ll a) { k+=n-1; dat[k]=a; while(k>0) { k=(k-1)/2; dat[k]=min(dat[k*2+1],dat[2*k+2]); } } ll query (ll a, ll b, ll k,ll l, ll r) { if(r<=a||b<=l) return INF; if(a<=l&&r<=b) return dat[k]; else { ll vl=query(a,b,k*2+1,l,(l+r)/2); ll vr=query(a,b,k*2+2,(l+r)/2,r); return min(vl,vr); } } int main() { ll N,Q;cin>>N>>Q; vector> vec(Q); for(ll i=0;i>get<0>(vec[i])>>get<1>(vec[i])>>get<2>(vec[i]); get<0>(vec[i])--;get<1>(vec[i])--; } sort(all(vec)); vec.push_back(make_tuple(N,N+1,0)); priority_queue> S; vector A(N); ll R=N-1; ll t=1; ll ind=-1; ll i=0; while(i(vec[ind+1])>i&&i<=R) { A[i]=t; i++; } else if(get<0>(vec[ind+1])==i) { if(get<2>(vec[ind+1])>t) { S.push(make_pair(t,R)); t=get<2>(vec[ind+1]); } else { S.push(make_pair(get<2>(vec[ind+1]),get<1>(vec[ind+1]))); } ind++; } else { auto x=S.top();S.pop(); t=x.first;R=x.second; } } init(N); for(ll i=0;i(vec[i]),get<1>(vec[i])+1,0,0,n); if(k!=get<2>(vec[i])) { cout<<-1<