//------------------------------>> tsukasa_diary's template <<------------------------------//
#include <bits/stdc++.h>
using namespace std;

#define for_(i,a,b) for(int i=(a);i<(b);++i)
#define for_rev(i,a,b) for(int i=(a);i>=(b);--i)
#define allof(a) (a).begin(),(a).end()
#define minit(a,b) memset(a,b,sizeof(a))

using lint = long long;
using pii = pair< int, int >;

template< typename T > using Vec = vector< T >;

template< typename T > bool in_range(T x, T lb, T ub) { return lb <= x && x < ub; }
template< typename T > bool in_range(T x, T y, T lb, T ub) { return in_range(x, lb, ub) && in_range(y, lb, ub); }

template< typename T > void modAdd(T& a, T b, T mod) { a = (a + b + mod) % mod; }
template< typename T > void modMul(T& a, T b, T mod) { a = (a * b) % mod; }
template< typename T > void minUpdate(T& a, T b) { a = min(a, b); }
template< typename T > void maxUpdate(T& a, T b) { a = max(a, b); }

int bitCount(int x) { return __builtin_popcount(x); }
int bitCount(lint x) { return __builtin_popcountll(x); }

const int dx[4] = {0,1,0,-1}, dy[4] = {-1,0,1,0};
const int Dx[8] = {0,1,1,1,0,-1,-1,-1}, Dy[8] = {-1,-1,0,1,1,1,0,-1};
const double EPS = 1e-9;
const double PI = acos(-1);

//--------------8---------------->> coding space <<-----------------8-------------//

template< typename DATA, class CALC, DATA FAIL, DATA LAZY_INIT >
class SegmentTreeLazy {
private:
	int size__;
	Vec< DATA > data, lazy;
	
	inline int left_t(int k) { return (k << 1) + 1; }
	inline int right_t(int k) { return (k << 1) + 2; }
	inline int center(int l, int r) { return (l + r) >> 1; }
	
private:
	DATA calc(DATA d1, DATA d2) { return CALC().calc(d1, d2); }
	
	void lazyCalc(int k, DATA val) { lazy[k] = CALC().lazyCalc(lazy[k], val); }
	
	inline void lazyEval(int l, int r, int k) {
		data[k] = CALC().lazyEval(data[k], lazy[k], l, r);
		
		if (k < size__ - 1) {
			lazyCalc(left_t(k), lazy[k]);
			lazyCalc(right_t(k), lazy[k]);
		}
		
		lazy[k] = LAZY_INIT;
	}
	
	inline void updateAt(int k) { data[k] = calc(data[left_t(k)], data[right_t(k)]); }
	
	void update(int a, int b, DATA x, int k, int l, int r) {
		lazyEval(l, r, k);
		
		if (r <= a || b <= l) return;
		if (a <= l && r <= b) {
			lazyCalc(k, x);
			lazyEval(l, r, k);
			return;
		}
		
		update(a, b, x, left_t(k), l, center(l, r));
		update(a, b, x, right_t(k), center(l, r), r);
		updateAt(k);
	}
	
	DATA query(int a, int b, int k, int l, int r) {
		lazyEval(l, r, k);
		
		if (r <= a || b <= l) return FAIL;
		if (a <= l && r <= b) return data[k];
		DATA res =  calc(query(a, b, left_t(k), l, center(l, r)),
						 query(a, b, right_t(k), center(l, r), r));
		
		updateAt(k);
		return res;
	}
	
public:
	SegmentTreeLazy() {}
	
	SegmentTreeLazy(int n, DATA ini) {
		for (size__ = 1; size__ < n; size__ <<= 1);
		data.assign(2 * size__ - 1, ini);
		lazy.assign(2 * size__ - 1, LAZY_INIT);
	}
	
	void update(int a, int b, DATA x) { update(a, b, x, 0, 0, size__); }
	
	DATA query(int a, int b) { return query(a, b, 0, 0, size__); }
	
	int size() { return size__; }
};

template< typename T >
class LazyMinCalc {
public:
	inline T calc(T d1, T d2) { return min(d1, d2); }
	inline T lazyCalc(T lz, T val) { return min(lz, val); }
	inline T lazyEval(T d, T lz, int l, int r) { return min(d, lz); }
};



int main() {
	int N, M;
	cin >> N >> M;
	
	struct Query {
		int L, R;
		lint C;
		bool operator < (const Query& o) const {
			if (L < o.L) return  true;
			return false;
		}
	};
	
	vector< Query > q;
	for (int i=0; i<M; ++i) {
		int L, R, C;
		cin >> L >> R >> C;
		--L; --R;
		q.push_back(Query{L, R, C});
	}
	
	sort(allof(q));
	
	const lint INIT_DST = 1LL << 60;
	SegmentTreeLazy< lint, LazyMinCalc< lint >, INIT_DST, INIT_DST > seg(N, INIT_DST);
	seg.update(0, 1, 0);
	
	for (int i=0; i<M; ++i) {
		lint val = seg.query(q[i].L, q[i].L + 1);
		seg.update(q[i].L, q[i].R+1, val + q[i].C);
	}
	
	lint ans = seg.query(N-1, N);
	cout << (ans == INIT_DST ? -1 : ans) << endl;
}
//--------------8---------------->> coding space <<-----------------8-------------//

Measured memory_bytes: 6000