#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>
#include<boost/operators.hpp>
#include<boost/dynamic_bitset.hpp>

namespace adaptor = boost::adaptors;
using index_t = std::size_t;

template<class T>using p_queue=std::priority_queue<T, std::vector<T>, std::greater<>>;
template<class T>std::vector<boost::optional<T>> dijkstra(std::vector<std::map<index_t, T>>const& edge, index_t start)
{
	p_queue<std::pair<T, index_t>> queue;
	queue.emplace(T(), start);
	std::vector<boost::optional<T>> ret(edge.size());
	while (queue.size())
	{
		auto top = queue.top();
		queue.pop();
		if (ret[top.second])
		{
			continue;
		}
		ret[top.second] = top.first;
		for (auto&& p : edge[top.second])
		{
			queue.emplace(top.first + p.second, p.first);
		}
	}
	return ret;
}


void Main()
{
	int N, M;
	std::cin >> N >> M;
	std::vector<std::map<index_t, std::int64_t>>edge(N);
	for (auto _ : boost::irange(0, M))
	{
		int L, R;
		std::int64_t C;
		std::cin >> L >> R >> C;
		--L; --R;
		edge[L].emplace(R, C);
	}
	for (auto i : boost::irange(1, N))
	{
		edge[i].emplace(i - 1, 0);
	}
	auto result = dijkstra(edge, 0);
	std::cout << (result.back() ? *result.back() : -1) << std::endl;
}

int main()
{
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	Main();
}