#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<ll,ll> P;
#define M 998244353
#define F first
#define S second
#define PB push_back
#define INF 100000000000000000
struct SEG{
	ll seg[1<<18];
	SEG(void){
		for(int i=0;i<1<<18;i++)seg[i]=INF;
	}
	void up(int a,ll x){
		a+=(1<<17)-1;
		seg[a]=min(seg[a],x);
		while(a>0){
			a=(a-1)/2;
			seg[a]=min(seg[a*2+1],seg[a*2+2]);	
		}
	}
	ll que(int a,int b,int l,int r,int k){
		if(b<l||r<a)return INF;
		if(a<=l&&r<=b)return seg[k];
		return min(que(a,b,l,(l+r-1)/2,k*2+1),que(a,b,(l+r+1)/2,r,k*2+2));
	}
};
ll n,dp[100005],m;
vector<P>r[100005];
SEG seg;
int main(void){
	cin>>n>>m;
	for(int i=0;i<n;i++)dp[i]=INF;
	for(int i=0;i<m;i++){
		ll l,y,c;
		cin>>l>>y>>c;
		r[--y].PB(P(--l,c));
	}
	dp[0]=0;
	for(int i=0;i<n;i++){
		for(int j=0;j<r[i].size();j++){
			ll l=r[i][j].F,c=r[i][j].S;
			dp[i]=min(dp[i],seg.que(l,i-1,0,(1<<17)-1,0)+c);
		}
		seg.up(i,dp[i]);
	}
	if(dp[n-1]==INF)dp[n-1]=-1;
	cout<<dp[n-1]<<endl;
}
