#include <bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
	#include <boost/multiprecision/cpp_int.hpp>
	#include <boost/multiprecision/cpp_dec_float.hpp>
	using bll = boost::multiprecision::cpp_int;
	using bdouble = boost::multiprecision::cpp_dec_float_100;
#endif
#ifdef LOCAL_DEV
	void debug_impl() { std::cerr << std::endl; }
	template<typename Head, typename... Tail> void debug_impl(Head head, Tail... tail) { std::cerr << " " << head << (sizeof...(tail) ? "," : ""); debug_impl(tail...); }
	#define debug(...) std::cerr << std::boolalpha << "(" << #__VA_ARGS__ << ") ="; debug_impl(__VA_ARGS__); std::cerr << std::noboolalpha;
#else
	#define debug(...)
#endif
#ifdef LOCAL_TEST
	#define BOOST_STACKTRACE_USE_ADDR2LINE
	#define BOOST_STACKTRACE_ADDR2LINE_LOCATION /usr/local/opt/binutils/bin/addr2line
	#define _GNU_SOURCE
	#include <boost/stacktrace.hpp>
	template<typename T> class dvector : public std::vector<T> {
	public:
		dvector() : std::vector<T>() {}
		explicit dvector(size_t n, const T& value = T()) : std::vector<T>(n, value) {}
		dvector(const std::vector<T>& v) : std::vector<T>(v) {}
		dvector(const std::initializer_list<T> il) : std::vector<T>(il) {}
		dvector(const typename std::vector<T>::iterator first, const typename std::vector<T>::iterator last) : std::vector<T>(first, last) {}
		dvector(const std::string::iterator first, const std::string::iterator last) : std::vector<T>(first, last) {}
		T& operator[](size_t n) {
			try { return this->at(n); } catch (const std::exception& e) {
				std::cerr << boost::stacktrace::stacktrace() << std::endl; return this->at(n);
			}
		}
		const T& operator[](size_t n) const {
			try { return this->at(n); } catch (const std::exception& e) {
				std::cerr << boost::stacktrace::stacktrace() << std::endl; return this->at(n);
			}
		}
	};
	class dbool {
	private:
		bool boolvalue;
	public:
		dbool() : boolvalue(false) {}
		dbool(bool b) : boolvalue(b) {}
		dbool(const dbool &b) : boolvalue(b.boolvalue) {}
		operator bool&() { return boolvalue; }
		operator const bool&() const { return boolvalue; }
	};
	template<typename T> std::ostream& operator<<(std::ostream& s, const dvector<T>& v) {
		for (int i = 0, len = v.size(); i < len; ++i){ s << v[i]; if (i < len - 1) s << "\t"; } return s; }
	template<typename T> std::ostream& operator<<(std::ostream& s, const dvector< dvector<T> >& vv) {
		for (int i = 0, len = vv.size(); i < len; ++i){ s << vv[i] << std::endl; } return s; }
	template<typename T> std::ostream& operator<<(std::ostream& s, const std::set<T>& se) {
		s << "{ "; for (auto itr = se.begin(); itr != se.end(); ++itr){ s << (*itr) << "\t"; } s << "}" << std::endl; return s; }
	template<typename T> std::ostream& operator<<(std::ostream& s, const std::multiset<T>& se) {
		s << "{ "; for (auto itr = se.begin(); itr != se.end(); ++itr){ s << (*itr) << "\t"; } s << "}" << std::endl; return s; }
	template<typename T1, typename T2> std::ostream& operator<<(std::ostream& s, const std::map<T1, T2>& m) {
		s << "{" << std::endl; for (auto itr = m.begin(); itr != m.end(); ++itr){ s << "\t" << (*itr).first << " : " << (*itr).second << std::endl; } s << "}" << std::endl; return s; }
	template<typename T1, typename T2> std::ostream& operator<<(std::ostream& s, const std::pair<T1, T2>& p) { 
		return s << "(" << p.first << ", " << p.second << ")"; }
	#define vector dvector
	#define bool dbool
#endif
//#define int long long
using ll = long long;
//constexpr int INF = 1e9;//INT_MAX=(1<<31)-1=2147483647
constexpr ll INF = (ll)1e18;//(1LL<<63)-1=9223372036854775807
constexpr ll MOD = (ll)1e9 + 7;
constexpr double EPS = 1e-9;
constexpr int dx[4]={1,0,-1,0};
constexpr int dy[4]={0,1,0,-1};
#define p(var) std::cout<<var<<std::endl
#define rep(i, n)   for(ll i=0, i##_length=(n); i< i##_length; ++i)
#define repeq(i, n) for(ll i=1, i##_length=(n); i<=i##_length; ++i)
#define all(v) (v).begin(), (v).end()
#define uniq(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
template<typename T> inline void pv(vector<T> &v) { for(ll i=0, N=v.size(); i<N; i++) std::cout << v[i] << " \n"[i==N-1]; }
template<typename T> inline T gcd(T a, T b) { return b ? gcd(b,a%b) : a; }
template<typename T> inline T lcm(T a, T b) { return a / gcd(a,  b) * b; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

/*-----8<-----template-----8<-----*/

/*
実装では木を 1-indexed の配列で表現している。
ノード k について, 親ノードは k/2, 子ノードは 2k, 2k+1 である。

LazySegmentTree(n, f, g, h, M1, OM0):= サイズ n の初期化。
	f は2つの区間の要素をマージする二項演算, 
	g は要素と作用素をマージする二項演算(第三引数は対応する区間の長さ), 
	h は作用素同士をマージする二項演算, M1 はモノイドの単位元, 
	OM0 は作用素の単位元である。
set(k,x):= k 番目の要素に x を代入する。
build():= セグメント木を構築する。
query(a,b):= 区間 [a,b) に対して二項演算した結果を返す。
update(a, b, x) := 区間 [a,b) に作用素 x を適用する。
operator[k] := k 番目の要素を返す。
*/
template< typename Monoid, typename OperatorMonoid = Monoid >
class LazySegmentTree {
public:
	using F = function< Monoid(Monoid, Monoid) >;
	using G = function< Monoid(Monoid, OperatorMonoid, ll) >;
	using H = function< OperatorMonoid(OperatorMonoid, OperatorMonoid) >;

	ll size;
	vector< Monoid > data;
	vector< OperatorMonoid > lazy;
	const F f;
	const G g;
	const H h;
	const Monoid M1;
	const OperatorMonoid OM0;

	LazySegmentTree(ll n, const F f, const G g, const H h, const Monoid &M1, const OperatorMonoid OM0)
		 : f(f), g(g), h(h), M1(M1), OM0(OM0) {
		size = 1;
		while(size < n) size <<= 1;
		data.assign(2 * size, M1);
		lazy.assign(2 * size, OM0);
	}

	void set(ll k, const Monoid &x) {
		data[k + size] = x;
	}

	void build() {
		for(ll k = size - 1; k > 0; k--) {
			data[k] = f(data[2 * k + 0], data[2 * k + 1]);
		}
	}
	
	void propagate(ll k, ll len) {
		if(lazy[k] != OM0) {
			if(k < size) {
				lazy[2 * k + 0] = h(lazy[2 * k + 0], lazy[k]);
				lazy[2 * k + 1] = h(lazy[2 * k + 1], lazy[k]);
			}
			data[k] = g(data[k], lazy[k], len);
			lazy[k] = OM0;
		}
	}

	Monoid update(ll a, ll b, const OperatorMonoid &x, ll k, ll l, ll r) {
		propagate(k, r - l);
		if(r <= a || b <= l) {
			return data[k];
		} else if(a <= l && r <= b) {
			lazy[k] = h(lazy[k], x);
			propagate(k, r - l);
			return data[k];
		} else {
			return data[k] = f(update(a, b, x, 2 * k + 0, l, (l + r) >> 1),
				update(a, b, x, 2 * k + 1, (l + r) >> 1, r));
		}
	}

	Monoid update(ll a, ll b, const OperatorMonoid &x) {
		return update(a, b, x, 1, 0, size);
	}

	Monoid query(ll a, ll b, ll k, ll l, ll r) {
		propagate(k, r - l);
		if(r <= a || b <= l) {
			return M1;
		} else if(a <= l && r <= b) {
			return data[k];
		} else {
			return f(query(a, b, 2 * k + 0, l, (l + r) >> 1),
				query(a, b, 2 * k + 1, (l + r) >> 1, r));
		}
	}

	Monoid query(ll a, ll b) {
		return query(a, b, 1, 0, size);
	}

	Monoid operator[](const ll &k) {
		return query(k, k + 1);
	}
};

/*-----8<-----library-----8<-----*/

class D
{
private:
	/* data */
public:
	ll l,r,c;
	D(/* args */);

};


constexpr ll N_MAX = 100000;
constexpr ll M_MAX = 100000;
constexpr ll C_I_MAX = 1000000000;

ll N, M;
vector<ll> L;
vector<ll> R;
vector<ll> C;

void solve() {
  	scanf("%lld%lld", &N, &M);
	L.assign(M, 0);
	R.assign(M, 0);
	C.assign(M, 0);
	rep(i, M) scanf("%lld%lld%lld", &L[i], &R[i], &C[i]);
	
	vector<tuple<ll,ll,ll>> a(M);
	rep(i,M){
		L[i]--;
		//R[i]--;
		a[i]=make_tuple(L[i], R[i], C[i]);
	}
	sort(all(a));
	
	/*
	rep(i,M){
		debug(get<0>(a[i]), get<1>(a[i]), get<2>(a[i]));
	}
	*/

	ll ans = 0;

	auto minlambda=[](ll x,ll y){return min(x,y);};
	auto minlambda1=[](ll x,ll y,ll l){return min(x,y);};
	LazySegmentTree<ll> st(N, minlambda, minlambda1, minlambda, INF, INF);

	rep(i,M){
		if(get<0>(a[i])==0){
			st.update(get<0>(a[i]), get<1>(a[i]), get<2>(a[i]));
		}else{
			ll t=st.query(get<0>(a[i]), get<1>(a[i]));
			debug(t,t+get<2>(a[i]));
			st.update(get<0>(a[i]), get<1>(a[i]), t+get<2>(a[i]));
		}
	}
	
	ans=st.query(N-1,N);
	if(ans==INF)ans=-1;
	printf("%lld\n", ans);
}

signed main() {
	solve();
	return 0;
}


Measured memory_bytes: 8960