#include <bits/stdc++.h>
template <typename T>
void view(T e) {
  std::cout << e << std::endl;
}
template <typename T>
void view(const std::vector<T>& v) {
  for (const auto& e : v) {
    std::cout << e << " ";
  }
  std::cout << std::endl;
}
template <typename T>
void view(const std::vector<std::vector<T>>& vv) {
  for (const auto& v : vv) {
    view(v);
  }
}
using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
struct Dijkstra {
  struct edge {
    int to;
    long long cost;
    edge(int to, long long cost) : to(to), cost(cost) {}
  };
  const long long INF = 1LL << 60;
  int v;
  int s;
  vector<vector<edge>> g;
  vector<long long> dist;
  priority_queue<pair<long long, int>, vector<pair<long long, int>>,
                 greater<pair<long long, int>>>
      que;
  Dijkstra(int v, int s) : v(v), s(s), g(v), dist(v, INF) {
    dist[s] = 0;
    que.push(pair<long long, int>(0, s));
  }
  void add_edge(int start, int to, long long cost) {
    g[start].emplace_back(to, cost);
  }
  void build() {
    while (!que.empty()) {
      pair<long long, int> p = que.top();
      que.pop();
      int current = p.second;
      if (dist[current] < p.first) continue;
      for (edge& e : g[current]) {
        if (dist[e.to] > dist[current] + e.cost) {
          dist[e.to] = dist[current] + e.cost;
          que.push(pair<long long, int>(dist[e.to], e.to));
        }
      }
    }
  }
  long long shortest_path_value(int t) { return dist[t]; }
};
void Main() {
  int N, M;
  cin >> N >> M;
  Dijkstra dijkstra(N, 0);
  for (int i = (0); i < (M); ++i) {
    int L, R, C;
    cin >> L >> R >> C;
    --L;
    --R;
    dijkstra.add_edge(L, R, C);
  }
  for (int i = (0); i < (N - 1); ++i) {
    dijkstra.add_edge(i + 1, i, 0);
  }
  dijkstra.build();
  cout << dijkstra.shortest_path_value(N - 1) << endl;
}
int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}
