#include <bits/stdc++.h>
using namespace std;
struct Node {
  int num;
  vector<pair<int, int>> edge;
  bool confirmed;
  int mincost;
};
bool operator<(const Node node1, const Node node2) {
  return node1.mincost < node2.mincost;
}
pair<vector<pair<int, int>>::iterator, vector<pair<int, int>>::iterator>
dijkstra1(vector<Node> Nodex) {
  vector<pair<int, int>> c;
  while (Nodex.size() != 0) {
    vector<Node>::iterator x = min_element(Nodex.begin(), Nodex.end());
    x->confirmed = true;
    c.push_back(make_pair(x->num, x->mincost));
    for (auto i = x->edge.begin(); i < x->edge.end(); i++) {
      vector<Node>::iterator k = Nodex.end();
      for (vector<Node>::iterator j = Nodex.begin(); j < Nodex.end(); j++) {
        if (j->num == i->first) {
          k = j;
          break;
        }
      }
      if (k != Nodex.end()) {
        if (k->mincost == 1000000000) {
          k->mincost = x->mincost + i->second;
        } else {
          k->mincost = min(k->mincost, x->mincost + i->second);
        }
      }
    }
    Nodex.erase(x);
  }
  sort(c.begin(), c.end());
  return make_pair(c.begin(), c.end());
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<Node> Nodes(n);
  for (int i = 0; i < n; i++) {
    Nodes[i].num = i;
    Nodes[i].confirmed = false;
    if (i == 0) {
      Nodes[i].mincost = 0;
    } else {
      Nodes[i].mincost = 1000000000;
    }
  }
  for (int i = 0; i < m; i++) {
    int l, r, c;
    cin >> l >> r >> c;
    for (int j = l - 1; j < r; j++) {
      for (int k = j + 1; k < r; k++) {
        Nodes[j].edge.push_back(make_pair(k, c));
      }
    }
  }
  pair<vector<pair<int, int>>::iterator, vector<pair<int, int>>::iterator> d =
      dijkstra1(Nodes);
  vector<pair<int, int>>::iterator i = --d.second;
  if ((*i).second == 1000000000) {
    cout << -1 << endl;
  } else {
    cout << (*i).second << endl;
  }
}
