#include using namespace std; #define ALL(x) begin(x),end(x) #define rep(i,n) for(int i=0;i<(n);i++) #define debug(v) cout<<#v<<":";for(auto x:v){cout<bool chmax(T &a,const T &b){if(abool chmin(T &a,const T &b){if(b ostream &operator<<(ostream &os,const vector&v){ for(int i=0;i<(int)v.size();i++) os< istream &operator>>(istream &is,vector&v){ for(T &x:v)is>>x; return is; } template struct LazySegmentTree{ using F=function; using G=function; using H=function; private: int sz,height; vector data; vector lazy; // propagate lazy value -> data (node k) inline void propagate(int k){ if(lazy[k]!=OM0){ if(k0;k--) data[k]=f(data[2*k+0],data[2*k+1]); } void update(int a,int b,const OperatorMonoid &x){ update(a,b,x,1,0,sz); } Monoid query(int a,int b){ return query(a,b,1,0,sz); } Monoid operator[](const int &k){ return query(k,k+1); } }; // range set range min using M=ll; using OM=ll; const M M1=LINF; const OM OM0=-LINF; M segf(M a,M b){ return (ab?a:b); // } // M segg(M a,OM b){ // return (b==OM0?a:b); // } // OM segh(OM a,OM b){ // return (b==OM0?a:b); // } // // range add range min // using M=ll; // using OM=ll; // const M M1=LINF; // const OM OM0=0; // M segf(M a,M b){ // return (ab?a:b); // } // M segg(M a,OM b){ // return a+b; // } // OM segh(OM a,OM b){ // return a+b; // } // // range set range sum (sum, count) // using M=pair; // using OM=ll; // const M M1=M(0,0); // const OM OM0=-LINF; // M segf(M a,M b){ // return M(a.first+b.first,a.second+b.second); // } // M segg(M a,OM b){ // return M(a.second*b,a.second); // } // OM segh(OM a,OM b){ // return (b==OM0?a:b); // } // // range add range sum (sum, count) // using M=pair; // using OM=ll; // const M M1=M(0,0); // const OM OM0=0; // M segf(M a,M b){ // return M(a.first+b.first,a.second+b.second); // } // M segg(M a,OM b){ // return M(a.first+a.second*b,a.second); // } // OM segh(OM a,OM b){ // return a+b; // } signed main(){ int N,Q;cin>>N>>Q; LazySegmentTree seg(N,segf,segg,segh,M1,OM0); rep(i,N) seg.set(i,0); seg.build(); using T=tuple; vector V; rep(i,Q){ int l,r;ll B;cin>>l>>r>>B;l--; V.emplace_back(B,l,r); } sort(ALL(V)); reverse(ALL(V)); for(auto [B,l,r]:V){ seg.update(l,r,B); } for(auto [B,l,r]:V){ if(seg.query(l,r)!=B){ cout<<-1<