#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 7;
const int INF = 0x3f3f3f3f;
int head[maxn << 1];
struct Edge {
  int to, next;
  int w;
} edge[maxn << 1];
int tot;
void init() {
  memset(head, -1, sizeof(head));
  tot = 0;
}
void addedge(int u, int v, int w) {
  edge[tot].to = v;
  edge[tot].w = w;
  edge[tot].next = head[u];
  head[u] = tot++;
}
struct node {
  int v;
  int w;
  node(int _v = 0, int _w = 0) : v(_v), w(_w) {}
  bool operator<(const node &r) const { return w > r.w; }
};
int dist[maxn];
bool vis[maxn];
priority_queue<node> pq;
void Dijkstra(int n, int start) {
  memset(vis, false, sizeof(vis));
  for (int i = 1; i <= n; i++) dist[i] = INF;
  dist[start] = 0;
  while (!pq.empty()) pq.pop();
  pq.push(node(start, 0));
  while (!pq.empty()) {
    node k = pq.top();
    pq.pop();
    int u = k.v;
    if (vis[u]) continue;
    vis[u] = true;
    for (int i = head[u]; i != -1; i = edge[i].next) {
      int v = edge[i].to;
      int w = edge[i].w;
      if (!vis[v] && dist[v] > dist[u] + w) {
        dist[v] = dist[u] + w;
        pq.push(node(v, dist[v]));
      }
    }
  }
}
int main() {
  int n, m;
  while (~scanf("%d%d", &n, &m)) {
    init();
    for (int i = 1; i < n; i++) {
      addedge(i + 1, i, 0);
    }
    for (int i = 1; i <= m; i++) {
      int L, R, w;
      scanf("%d%d%d", &L, &R, &w);
      addedge(L, R, w);
    }
    Dijkstra(n, 1);
    if (dist[n] == INF) dist[n] = -1;
    printf("%d\n", dist[n]);
  }
  return 0;
}
