#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int maxn = 1e5 + 7;
const int mod = 1e9 + 7;
struct Edge {
  int v;
  long long cost;
  Edge(int _v = 0, int _cost = 0) : v(_v), cost(_cost) {}
};
vector<Edge> edge[maxn];
void addedge(int u, int v, int cost) { edge[u].push_back(Edge(v, cost)); }
struct node {
  int v;
  long long cost;
  node(int _v = 0, int _cost = 0) : v(_v), cost(_cost) {}
  bool operator<(const node &r) const { return cost > r.cost; }
};
long long dist[maxn];
bool vis[maxn];
priority_queue<node> pq;
void Dijkstra(int n, int start) {
  memset(vis, false, sizeof(vis));
  for (int i = 0; i < n; i++) dist[i] = INF;
  dist[start] = 0;
  while (!pq.empty()) pq.pop();
  pq.push(node(start, 0));
  node k;
  while (!pq.empty()) {
    k = pq.top();
    pq.pop();
    int u = k.v;
    if (vis[u]) continue;
    vis[u] = true;
    for (int i = 0; i < edge[u].size(); i++) {
      int v = edge[u][i].v;
      int cost = edge[u][i].cost;
      if (!vis[v] && dist[v] > dist[u] + cost) {
        dist[v] = dist[u] + cost;
        pq.push(node(v, dist[v]));
      }
    }
  }
}
int main() {
  int n, m;
  while (cin >> n >> m) {
    for (int i = 0; i < n; i++) {
      edge[i].clear();
    }
    for (int i = 1; i < n; i++) {
      addedge(i, i - 1, 0);
    }
    for (int i = 1; i <= m; i++) {
      int u, v;
      long long w;
      cin >> u >> v >> w;
      u--, v--;
      addedge(u, v, w);
    }
    Dijkstra(n, 0);
    cout << (dist[n - 1] == INF ? -1 : dist[n - 1]) << endl;
  }
  return 0;
}
