#include <bits/stdc++.h>
using namespace std;
struct edge {
  int to;
  long long dist, cost;
};
int N, M;
long long length[110000];
long long d[110000];
int main() {
  scanf("%d%d", &N, &M);
  vector<pair<pair<int, int>, long long> > graph;
  for (auto i = 0; i < M; i++) {
    int l, r;
    long long c;
    scanf("%d%d%ld", &l, &r, &c);
    graph.push_back(pair<pair<int, int>, long long>(pair<int, int>(l, r), c));
  }
  graph.push_back(pair<pair<int, int>, long long>(pair<int, int>(1, 1), 0));
  sort(graph.begin(), graph.end());
  memset(d, -1, sizeof(d));
  d[0] = 0;
  set<int> st{0};
  for (auto i = 1; i < graph.size(); i++) {
    for (auto j : st) {
      int jr = graph[j].first.second;
      int il = graph[i].first.first;
      if (il <= jr) {
        if (d[i] == -1)
          d[i] = graph[i].second + d[j];
        else
          d[i] = min(d[i], graph[i].second + d[j]);
      } else {
        st.erase(j);
      }
    }
    if (d[i] != -1) st.insert(i);
  }
  long long res = LLONG_MAX;
  for (auto i = 0; i < graph.size(); i++) {
    if (graph[i].first.second == N) {
      res = min(res, d[i]);
    }
  }
  printf("%d\n", res);
}
