#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  char ch = getchar();
  long long nega = 1;
  while (!isdigit(ch)) {
    if (ch == '-') nega = -1;
    ch = getchar();
  }
  long long ans = 0;
  while (isdigit(ch)) {
    ans = ans * 10 + ch - 48;
    ch = getchar();
  }
  if (nega == -1) return -ans;
  return ans;
}
long long n;
struct Edge {
  long long v, w, nxt;
};
Edge edge[100005 * 2];
struct Node {
  long long pl, dat;
  bool operator<(const Node &x) const { return dat > x.dat; }
};
long long first[100005], ss;
long long dis[100005];
bool inq[100005];
void add(long long u, long long v, long long w) {
  ss++;
  edge[ss].v = v, edge[ss].w = w, edge[ss].nxt = first[u];
  first[u] = ss;
}
signed main() {
  long long n, m;
  cin >> n >> m;
  for (long long i = 1; i < n; i++) add(i + 1, i, 0);
  for (long long i = 1; i <= m; i++) {
    long long u = read(), v = read(), w = read();
    add(u, v, w);
  }
  for (long long i = 2; i <= n; i++) dis[i] = 1.5e15;
  queue<Node> q;
  q.push((Node){1, 0});
  while (!q.empty()) {
    Node x = q.front();
    q.pop();
    long long u = x.pl;
    if (dis[u] != x.dat) continue;
    inq[u] = 0;
    for (long long i = first[u]; i != 0; i = edge[i].nxt) {
      long long v = edge[i].v;
      if (dis[v] > dis[u] + edge[i].w) {
        dis[v] = dis[u] + edge[i].w;
        q.push((Node){v, dis[v]});
      }
    }
  }
  if (dis[n] != 1.5e15)
    cout << dis[n] << endl;
  else
    cout << "-1\n";
  return 0;
}
