#include <cstdio>
#include <vector>
#include <queue>
#include <utility>
#include <functional>

struct edge
{
  int to;
  long long cost;
};
std::vector<edge> edges[100000];
  
int main()
{
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i < n; ++i)
  {
    edges[i].emplace_back(edge{i - 1, 0});
  }
  for (int i = 0; i < m; ++i)
  {
    int a, b;
    long long c;
    scanf("%d%d%lld", &a, &b, &c);
    --a, --b;
    edges[a].emplace_back(edge{b, c}); 
  }
  long long dist[100000];
  using pair = std::pair<long long, int>;
  std::fill(dist, dist + n, 1e18);
  dist[0] = 0;
  std::priority_queue<pair, std::vector<pair>, std::greater<pair>> q;
  q.emplace(0, 0);
  while (q.size() > 0)
  {
    auto p = q.top(); q.pop();
    if (p.first > dist[p.second]) continue;
    for (const auto& e : edges[p.second])
    {
      long long next = p.first + e.cost;
      if (dist[e.to] > next)
      {
        dist[e.to] = next;
        q.emplace(next, e.to);
      }
    }
  }
  printf("%lld\n", dist[n - 1] == 1e18 ? -1 : dist[n - 1]);
  return 0;
}