#include<iostream>
#include<algorithm>
#include<vector>
#include<climits>

using namespace std;

class Hen {
	unsigned long long L;
	unsigned long long R;
	unsigned long long C;
public:
	Hen() :L(0), R(0), C(0) {}
	Hen(unsigned long long l, unsigned long long r, unsigned long long c) :L(l), R(r), C(c) {}

	unsigned long long Left() {
		return L;
	}
	unsigned long long Right() {
		return R;
	}
	unsigned long long Cost() {
		return C;
	}

	bool operator<(const Hen& a) {
		return L < a.L;
	}
};

int main() {
	unsigned long long N, M;
	cin >> N >> M;

	vector<Hen> Hen_ary;
	for (unsigned long long i = 0; i < M; i++) {
		unsigned long long ll, rr, cc;
		cin >> ll >> rr >> cc;
		Hen_ary.push_back(Hen(ll, rr, cc));
	}

	sort(Hen_ary.begin(), Hen_ary.end());

	vector<unsigned long long> Dis(N, ULLONG_MAX);
	Dis[0] = 0ULL;

	for (vector<Hen>::size_type i = 0; i < M; i++) {

		//辺データ区間内の最小値を探す(ver2)
		//最小値は必ず左端！
		unsigned long long Cost_min = Dis[Hen_ary[i].Left() - 1];

		//辺が途切れていたらそこで終了
		if (Cost_min == LLONG_MAX) {
			cout << -1;
			return 0;
		}

		//辺データ区間内の、始点からの距離を更新
		for (vector<Hen>::size_type j = Hen_ary[i].Left() + 1; j <= Hen_ary[i].Right(); j++) {
			if (Dis[j - 1] > Hen_ary[i].Cost() + Cost_min) {
				Dis[j - 1] = Hen_ary[i].Cost() + Cost_min;
			}
		}
	}

	cout << Dis[N - 1];
	return 0;

}