#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9 + 7;
const long long LINF = 1e18;
using namespace std;
template <typename T>
void print(const vector<T> &x) {
  int n = x.size();
  for (int i = 0; i < (n); ++i) {
    cout << x[i];
    if (i != n - 1)
      cout << " ";
    else
      cout << endl;
  }
}
template <typename T>
void print(const vector<vector<T>> &x) {
  int n = x.size();
  for (int i = 0; i < (n); ++i) {
    for (int j = 0; j < (x[i].size()); ++j) {
      cout << x[i][j] << " ";
    }
    cout << endl;
  }
}
template <typename T>
void print(const vector<T> &x, int n) {
  for (int i = 0; i < (n); ++i) {
    cout << x[i];
    if (i != n - 1)
      cout << " ";
    else
      cout << endl;
  }
}
template <typename T>
void print(const vector<vector<T>> &x, int n, int m) {
  for (int i = 0; i < (n); ++i) {
    for (int j = 0; j < (m); ++j) {
      cout << x[i][j] << " ";
    }
    cout << endl;
  }
}
template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
void input_init() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}
struct In {
  long long l, r, c;
  In() {}
  In(long long l, long long r, long long c) : l(l), r(r), c(r) {}
};
typedef struct Edge {
  long long to, cost;
} Edge;
typedef struct Info {
  long long dist, from;
} Info;
void dijkstra(vector<Info> &dp, int s, const vector<vector<Edge>> &g) {
  priority_queue<pair<long long, long long>, vector<pair<long long, long long>>,
                 greater<pair<long long, long long>>>
      pq;
  dp[s].dist = 0;
  pq.push({0, s});
  while (!pq.empty()) {
    pair<long long, long long> p = pq.top();
    pq.pop();
    int v = p.second;
    for (auto &&e : g[v]) {
      if (dp[e.to].dist > dp[v].dist + e.cost) {
        dp[e.to].dist = dp[v].dist + e.cost;
        dp[e.to].from = v;
        pq.push({dp[e.to].dist, e.to});
      }
    }
  }
}
int main(int argc, char const *argv[]) {
  int n, m;
  cin >> n >> m;
  vector<In> a(m);
  for (int i = 0; i < (m); ++i) cin >> a[i].l >> a[i].r >> a[i].c;
  vector<vector<Edge>> g(n + 10);
  for (int i = 0; i < (m); ++i) {
    g[a[i].l].push_back({a[i].r, a[i].c});
  }
  for (int i = 1; i <= n; ++i) g[i].push_back({i - 1, 0});
  vector<Info> dp(n + 10, {INF, INF});
  dijkstra(dp, 1, g);
  cout << dp[n].dist << endl;
  return 0;
}
