#include <bits/stdc++.h>
using namespace std;
struct Network {
 private:
  vector<map<long long, long long>> adj;
  bool directed;

 public:
  explicit Network(bool directed) : directed(directed) {}
  void add_edge(long long from, long long to, long long weight) {
    assert(from >= 0);
    assert(to >= 0);
    assert(weight >= 0);
    if (adj.size() < max(from, to) + 1) {
      adj.resize(max(from, to) + 1);
    }
    adj.at(from)[to] = weight;
    if (!directed) {
      adj.at(to)[from] = weight;
    }
  }
  long long get_weight(long long from, long long to) const {
    return adj.at(from).at(to);
  }
  void dijkstra(long long src, vector<long long>& out) {
    const long long n = adj.size();
    out.resize(n);
    fill(out.begin(), out.end(), -1);
    out.at(src) = 0;
    priority_queue<pair<long long, long long>,
                   vector<pair<long long, long long>>,
                   greater<pair<long long, long long>>>
        que;
    que.emplace(0, src);
    while (!que.empty()) {
      const auto p = que.top();
      que.pop();
      const long long v = p.second;
      for (auto nxt : adj[v]) {
        if (out[nxt.first] == -1 || out[nxt.first] > out[v] + nxt.second) {
          out[nxt.first] = out[v] + nxt.second;
          que.emplace(out[nxt.first], nxt.first);
        }
      }
    }
  }
  void floyd_warhsall(vector<vector<long long>>& out) {
    const long long n = adj.size();
    out.resize(adj.size(), vector<long long>(n, -1));
    for (long long i = 0; i < n; ++i) {
      for (auto p : adj.at(i)) {
        out.at(i).at(p.first) = p.second;
      }
      out.at(i).at(i) = 0;
    }
    for (long long k = 0; k < n; ++k) {
      for (long long i = 0; i < n; ++i) {
        if (out.at(i).at(k) == -1) {
          continue;
        }
        const long long dik = out.at(i).at(k);
        for (long long j = 0; j < n; ++j) {
          if (out.at(k).at(j) == -1) {
            continue;
          }
          const long long dkj = out.at(k).at(j);
          const long long dij = out.at(i).at(j);
          if (dij == -1 || dij > dik + dkj) {
            out.at(i).at(j) = dik + dkj;
          }
        }
      }
    }
  }
};
int main() {
  long long n, m;
  cin >> n >> m;
  Network net(true);
  for (long long i = 0; i < (m); ++i) {
    long long li, ri, ci;
    cin >> li >> ri >> ci;
    li--;
    ri--;
    net.add_edge(li, ri, ci);
  }
  for (long long i = 0; i < (n - 1); ++i) {
    net.add_edge(i + 1, i, 0);
  }
  vector<long long> dist;
  net.dijkstra(0, dist);
  cout << dist[n - 1] << endl;
  return 0;
}
