/*
khôi luoi document nên mình làm thay khôi.
also for some reason dùng x^2+c các ban se bi TLE on test "4", ngay ca voi x0 và c random.
-normie-
*/
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define rep(i,n) for(int64_t i=0;i < (int64_t)(n);i++)
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define FILE_IN "birds.inp"
#define FILE_OUT "birds.out"
#define ofile freopen(FILE_IN,"r",stdin);freopen(FILE_OUT,"w",stdout)
#define fio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define nfio cin.tie(0);cout.tie(0)
#define max(x,y) (((x)>(y))?(x):(y))
#define min(x,y) (((x)<(y))?(x):(y))
#define ord(a,b,c) ((a>=b)and(b>=c))
#define MOD (ll(1000000007))
#define MAX 300001
#define mag 320
#define p1 first
#define p2 second.first
#define p3 second.second
#define fi first
#define se second
#define pow2(x) (ll(1)<<x)
#define pii pair<int,int>
#define piii pair<int,pii>
#define pll pair<ll,ll>
#define plll pair<ll,pll>
#define For(i,__,___) for(int i=__;i<=___;i++)
#define Rep(i,__,___) for(int i=__;i>=___;i--)
#define ordered_set tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update>
#define endl "\n"
#define bi BigInt
typedef long long ll;
#define pi 3.1415926535897
//------START-----------//
struct cmp
{
	int operator()(pll a, pll b)
	{
		return (a.se>b.se);
	}
};
struct graph{
	private:
	vector<vector<pll>> gt;
	vector<ll> dist;
	priority_queue<pll,vector<pll>,cmp> bruh;
	ll n;
	
	void proc(pll cur)
	{
		ll v=cur.fi,t=cur.se;
		if (t>dist[v]) return;
		for (auto g: gt[v])
			if (dist[g.fi]>dist[v]+g.se)
		{
			dist[g.fi]=dist[v]+g.se;
			bruh.push({g.fi,dist[v]+g.se});
		}
	}
	public:
	graph (ll n)
	{
		this->n=n;
		for (ll i=0;i<n;i++)
		{
			gt.push_back({});
			dist.push_back(0);
		}
	}
	void addEdge (ll a, ll b, ll c)
	{
		gt[a].push_back({b,c});
	}
	vector<ll> dijkstra(ll s)
	{
		for (ll i=0;i<n;i++)
		{
			dist[i]=1e9;
		}
		dist[s]=0;
		bruh.push({s,0});
		while(bruh.size())
		{
			auto toproc(bruh.top());
			bruh.pop();
			proc(toproc);
		}
		return dist;
	}
};
//------END-----------//
ll n,m,k,c[501],arr[100001],dy[100001],t,t1,i,j,res;
vector<ll> gt[51];
int main()
{
	cin>>n>>m;
	graph gr(n+1);
	for (i=1;i<n;i++) gr.addEdge(i+1,i,0);
	for (i=0;i<m;i++)
	{
		ll a,b,c;
		cin>>a>>b>>c;
		gr.addEdge(a,b,c);
	}
	vector<ll> res=gr.dijkstra(1);
	if (res[n]==1e9) cout<<-1; else cout<<res[n];
}