#include <bits/stdc++.h>
using namespace std;
const int M = 1e9 + 7;
const int N = 1e5 + 7;
int d[N];
int n, m;
bool vis[N];
struct HeadNode {
  int d, u;
  bool operator<(const HeadNode& rhs) const { return d > rhs.d; }
};
vector<HeadNode> arr[N];
void Dij() {
  fill(d + 1, d + n + 1, M);
  d[1] = 0;
  priority_queue<HeadNode> Q;
  Q.push({0, 1});
  while (!Q.empty()) {
    HeadNode x = Q.top();
    Q.pop();
    int u = x.u;
    if (vis[u]) continue;
    vis[u] = 1;
    for (int i = 0; i < arr[u].size(); i++) {
      HeadNode e = arr[u][i];
      if (d[e.d] > d[u] + e.u) {
        d[e.d] = d[u] + e.u;
        Q.push((HeadNode){d[e.d], e.d});
      }
    }
  }
}
int main() {
  int a, b, w;
  scanf("%d%d", &n, &m);
  for (int i = 2; i <= n; i++) {
    arr[i].push_back({i - 1, 0});
  }
  for (int i = 0; i < m; i++) {
    scanf("%d%d%d", &a, &b, &w);
    if (a < b) {
      swap(a, b);
    }
    arr[a].push_back({b, w});
  }
  Dij();
  cout << d[n] << endl;
  return 0;
}
