//#pragma GCC optimize(3)
#include <random>
#include <stdio.h>
#include <bits/stdc++.h>
#include <unordered_set>
#include <unordered_map>
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<int, int> pii;
#define Continue(x) { x; continue; }
#define Break(x) { x; break; }
#define Return(x) { x; return; }
#define P2(x) ((x) * (x))
#define lowbit(x) ((x) & -(x))
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define MEM(x, y) memset((x), (y), sizeof(x))
#define MEN(x, y, z) memset((x), (y), sizeof((x)[0]) * (z))
#define Diz(x) (lower_bound(dz.begin(), dz.end(), (x)) - dz.begin())
#define DISCRETE(x) (x).push_back(INT_MIN), sort((x).begin(), (x).end()), (x).erase(unique((x).begin(), (x).end()), (x).end())
#ifdef LOCAL
#define DEBUG(...) cout << ">> " << #__VA_ARGS__ << " =", PRT(__VA_ARGS__), cout << endl;
#define DEBUGS(...) cout << ">> " << #__VA_ARGS__ << " =", PRTS(__VA_ARGS__), cout << endl;
void PRT() {} template <typename S, typename... T> void PRT(S x, T ... y){ cout << " " << x; PRT(y...); }
void PRTS() {} template <typename S> void PRTS(S x) { for (auto v : x) cout << " " << v; }
#define TIME cout << "RunTime: " << clock() << "ms\n", 0
#define __int128_t long long
#else
#define DEBUG(...) ;
#define DEBUGS(...) ;
#define TIME 0
#endif

const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;
const int MOD = 1e9 + 7;
template<typename S, typename T> inline bool Min(S &a, const T &b){ return a > b ? a = b, true : false; }
template<typename S, typename T> inline bool Max(S &a, const T &b){ return a < b ? a = b, true : false; }
template<typename S, typename T> inline void Adm(S &a, const T &b){ a = (a + b) % MOD; if (a < 0) a += MOD; }
template<typename S, typename T> inline void Mum(S &a, const T &b){ a = 1LL * a * b % MOD; }
template<typename T> inline bool IsPri(T x) { if (x < 2) return false; for (T i = 2; i * i <= x; ++i) if (x % i == 0) return false; return true; }
template<typename T> inline T Gcd(T a, T b){ while (b){ T t = b; b = a % b; a = t; } return a; }
template<typename T> inline int BitCnt(T x){ int cnt = 0; while (x)++cnt, x &= x - 1; return cnt; }
template<typename T> inline T MDis(T x1, T y1, T x2, T y2){ return abs(x1 - x2) + abs(y1 - y2); }
template<typename T> inline T MDis(T x1, T y1, T z1, T x2, T y2, T z2){ return abs(x1 - x2) + abs(y1 - y2) + abs(z1 - z2); }
inline double EDis(double x1, double y1, double x2, double y2){ return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); }
inline double EDis(double x1, double y1, double z1, double x2, double y2, double z2){ return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2) + (z1 - z2) * (z1 - z2)); }
inline ll Pow(ll a, ll n) { ll t = 1; a %= MOD; while (n > 0) { if (n & 1) t = t * a % MOD; a = a * a % MOD, n >>= 1; } return t % MOD; }
#define gc p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin), p1 == p2) ? EOF : *p1++;
inline int read(){ static char buf[1000000], *p1 = buf, *p2 = buf; register int x = false; register char ch = gc; register bool sgn = false; while (ch != '-' && (ch < '0' || ch > '9')) ch = gc; if (ch == '-') sgn = true, ch = gc; while (ch >= '0'&& ch <= '9') x = (x << 1) + (x << 3) + (ch ^ 48), ch = gc; return sgn ? -x : x; }
//emplace unordered 能ll就开 函数内判非法

const int N = 1e5 + 100;
int n, m;
vector<pii> e[N];
ll dis[N];
bool vis[N];

ll Dijkstra()
{
	priority_queue<pli, vector<pli>, greater<pli>> pq;//代价 节点
	MEM(dis, 0x3f), dis[1] = 0, pq.push({ 0, 1 });
	while (!pq.empty())
	{
		int u = pq.top().second; pq.pop();
		if (vis[u])
			continue;
		if (u == n)
			return dis[u];
		if (u > 1 && dis[u - 1] > dis[u]) //可以不消耗代价往回走 表示可以到中间的任意一个位置
			dis[u - 1] = dis[u], pq.push({ dis[u], u - 1 });
		for (auto it : e[u])
		{
			int v = it.first, w = it.second;
			if (dis[v] > dis[u] + w)
				dis[v] = dis[u] + w, pq.push({ dis[v], v });
		}
	}
	return -1;
}
int main()
{
#ifdef LOCAL
	//freopen("C:/input.txt", "r", stdin);
	//freopen("C:/output.txt", "w", stdout);
#endif
	cin >> n >> m;
	for (int i = 1; i <= m; ++i)
	{
		int l, r, c;
		scanf("%d%d%d", &l, &r, &c);
		e[l].push_back({ r, c }); //直接移动到最远位置
	}
	cout << Dijkstra() << endl;

	return TIME;
}

Measured memory_bytes: 6400