#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 10;
const long long INF = 0xffffffff;
struct node {
  long long v, c;
  node(long long _v = 0, long long _c = 0) : v(_v), c(_c) {}
  bool operator<(const node &r) const { return c > r.c; }
};
struct Edge {
  long long v, cost;
  Edge(long long _v = 0, long long _cost = 0) : v(_v), cost(_cost) {}
};
vector<Edge> E[MAXN];
bool vis[MAXN];
long long dis[MAXN], n, m;
void init() {
  for (int i = 2; i <= n; i++) {
    E[i].push_back(Edge(i - 1, 0));
  }
}
long long Dijkstra() {
  int start = 1;
  memset(vis, false, sizeof(vis));
  for (int i = 1; i <= n; i++) dis[i] = INF;
  priority_queue<node> q;
  while (!q.empty()) q.pop();
  dis[start] = 0;
  q.push(node(start, 0));
  node x;
  while (!q.empty()) {
    x = q.top();
    q.pop();
    long long u = x.v;
    if (vis[u]) continue;
    vis[u] = true;
    for (unsigned int i = 0; i < E[u].size(); i++) {
      long long v = E[x.v][i].v;
      long long cost = E[u][i].cost;
      if (!vis[v] && dis[v] > dis[u] + cost) {
        dis[v] = dis[u] + cost;
        q.push(node(v, dis[v]));
      }
    }
  }
  return dis[n];
}
int main() {
  cin >> n >> m;
  long long l, r, c;
  for (int i = 0; i < m; i++) {
    cin >> l >> r >> c;
    E[l].push_back(Edge(r, c));
  }
  return 0;
}
