#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
using namespace std;
#define i64  long long
#define lint long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807
#define MOD_Q 1e9 + 7
#define MOD_A 998244353

#define int long long

template< typename T >
struct edge {
  int src, to;
  T cost;

  edge(int to, T cost) : src(-1), to(to), cost(cost) {}

  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}

  edge &operator=(const int &x) {
    to = x;
    return *this;
  }

  operator int() const { return to; }
};

template< typename T >
using Edges = vector< edge< T > >;
template< typename T >
using WeightedGraph = vector< Edges< T > >;
using UnWeightedGraph = vector< vector< int > >;
template< typename T >
using Matrix = vector< vector< T > >;

template< typename T >
vector< T > dijkstra(WeightedGraph< T > &g, int s) {
  const auto INF = numeric_limits< T >::max();
  vector< T > dist(g.size(), INF);

  using Pi = pair< T, int >;
  priority_queue< Pi, vector< Pi >, greater< Pi > > que;
  dist[s] = 0;
  que.emplace(dist[s], s);
  while(!que.empty()) {
    T cost;
    int idx;
    tie(cost, idx) = que.top();
    que.pop();
    if(dist[idx] < cost) continue;
    for(auto &e : g[idx]) {
      auto next_cost = cost + e.cost;
      if(dist[e.to] <= next_cost) continue;
      dist[e.to] = next_cost;
      que.emplace(dist[e.to], e.to);
    }
  }
  return dist;
}


void solve()
{
 
  int N,L;
  cin>>N>>L;
  WeightedGraph<int> es(N);

  for (int i = 0; i < L; i++)
  {
    int A,B,C;
    cin>>A>>B>>C;
    A--;
    B--;
    es[A].emplace_back(A,B,C);
  }

  for (int i = 1; i < N - 1 ; i++)
  {
    es[i+1].emplace_back(i+1,i,0);
  }

  vector<int> path = dijkstra(es,0);

  if(path[N-1] == I32_MAX) cout<<-1<<endl;
  else if(path.empty()) cout<<-1<<endl;
  else
  {
    cout<<path[N-1]<<endl;
  }
  
  
  

  
 
  return;
}
 
int main(int argc, const char *argv[])
{
 
  solve();
 
  return 0;
}