#include <bits/stdc++.h>
using namespace std;
struct YPO {
  long long int x, y;
};
long long int d[100050];
int main() {
  vector<struct YPO> G[100050];
  stack<struct YPO> q;
  long long int n, m, i, j, t;
  scanf("%lld%lld", &n, &m);
  long long int x, y, k;
  for (t = 0; t < m; t++) {
    scanf("%lld%lld%lld", &x, &y, &k);
    for (i = x; i <= y - 1; i++) {
      for (j = i + 1; j <= y; j++) {
        struct YPO a;
        a.x = k;
        a.y = j;
        G[i].push_back(a);
        a.x = k;
        a.y = i;
        G[j].push_back(a);
      }
    }
  }
  memset(d, -1, sizeof(d));
  struct YPO a;
  a.x = 0;
  a.y = 1;
  d[1] = 0;
  q.push(a);
  while (!q.empty()) {
    a = q.top();
    q.pop();
    if (d[a.y] != -1 && d[a.y] < a.x) continue;
    for (i = 0; i < G[a.y].size(); i++) {
      struct YPO b = G[a.y][i];
      if (d[b.y] == -1 || d[b.y] > d[a.y] + b.x) {
        d[b.y] = d[a.y] + b.x;
        b.x = d[a.y] + b.x;
        q.push(b);
      }
    }
  }
  printf("%lld\n", d[n]);
  return 0;
}
