#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
struct node
{
	ll r,c;
}u;
ll j,m,x,n,i,tr[100005],v,l,r,c;
vector<node>s[100005];
const ll inf=1e18;
ll lowbit(ll p){return p&-p;}
ll ask(ll p)
{
	ll ans=inf;
	while(p)
	{
		ans=min(ans,tr[p]);
		p-=lowbit(p);
	}
	return ans;
}
void modify(ll p)
{
	while(p<=n)
	{
		tr[p]=min(tr[p],v);
		p+=lowbit(p);
	}
}
int main()
{
	scanf("%lld%lld",&n,&m);
	for(i=1;i<=n;i++)tr[i]=inf;
	for(i=1;i<=m;i++)
	{
		scanf("%lld%lld%lld",&l,&r,&c);
		s[l].push_back((node){r,c});
	}
	v=0;
	modify(n);
	for(i=n-1;i>0;i--)
	{
		v=inf;
		for(j=0;j<s[i].size();j++)
		{
			u=s[i][j];
			v=min(v,ask(u.r)+u.c);
		}
		modify(i);
	}
	if(v>=inf)printf("-1\n");
	else printf("%lld\n",v);
	return 0;
} 