#include<bits/stdc++.h>
#include <array>
using namespace std;

#define rep(i, n) for(int i = 0; i < (n); i++)
using LL = long long;
using ULL = unsigned long long;


void solve() {
	int n; cin >> n;
	int m; cin >> m;
	vector<pair<int, LL>> LC, RC;
	vector<vector<pair<int, LL>>> edges(100000);
	rep(i, m) {
		int l, r; LL c;
		cin >> l >> r >> c; l--; r--;
		LC.push_back({ l, c });
		RC.push_back({ r, c });
		edges[l].push_back({ r, c });
	}
	sort(LC.begin(), LC.end());
	sort(RC.begin(), RC.end());
	rep(i, LC.size() - 1) {
		edges[LC[i + 1].first].push_back({ LC[i].first, 0 });
	}
	auto ritr = LC.rbegin();
	for(int i = 1; i < n; i++) {
		edges[i].push_back({ i - 1, 0 });
	}

	vector<LL> dp(100000); rep(i, n) dp[i] = -1;
	priority_queue<pair<LL, int>> q;
	q.push({ 0, 0 });
	while (!q.empty()) {
		auto top = q.top(); q.pop();
		int p = top.second; LL d = -top.first;
		if (dp[p] != -1) continue;
		dp[p] = d;
		rep(i, edges[p].size()) {
			q.push({ -(d + edges[p][i].second), edges[p][i].first });
		}
	}

	cout << dp[n - 1] << endl;
}

int main() {

	solve();

	return 0;
}
