#include <bits/stdc++.h>
#pragma GCC optimize("O2")
#pragma GCC target("avx2")
using namespace std;
const int TD = 17, PA = 1 << TD, AN = 100100, MA = AN * 4 * TD;
class IntervalEdgeTech {
 public:
  int Eto[PA * 5 + MA], Eco[PA * 5 + MA], Ene[PA * 5 + MA],
      Ehe[PA * 5 + AN * 2 + 2], EN, Nadd;
  long long D[PA * 5 + AN * 2 + 2];
  void adde(int v, int to, int co) {
    Eto[EN] = to;
    Eco[EN] = co;
    Ene[EN] = Ehe[v];
    Ehe[v] = EN++;
  }
  IntervalEdgeTech() : Ehe() {
    EN = 1;
    for (int i = PA * 2 - 1; i > 1; i--) adde(i << 1, i >> 1 << 1, 0);
    for (int i = 1; i <= (PA - 1); i++) {
      adde(i << 1 | 1, i << 2 | 1, 0);
      adde(i << 1 | 1, i << 2 | 3, 0);
    }
    for (int i = PA * 2; i < PA * 4; i += 2) adde(i + 1, i, 0);
    Nadd = PA * 4;
  }
  void AddE(int L1, int R1, int L2, int R2, int C) {
    for (L1 += PA, R1 += PA; L1 < R1; L1 >>= 1, R1 >>= 1) {
      if (L1 & 1) adde(L1++ << 1, Nadd, 0);
      if (R1 & 1) adde(--R1 << 1, Nadd, 0);
    }
    for (L2 += PA, R2 += PA; L2 < R2; L2 >>= 1, R2 >>= 1) {
      if (L2 & 1) adde(Nadd + 1, L2++ << 1 | 1, 0);
      if (R2 & 1) adde(Nadd + 1, --R2 << 1 | 1, 0);
    }
    adde(Nadd, Nadd + 1, C);
    Nadd += 2;
  }
  void dij(int v) {
    for (int i = 0; i < (PA * 5 + AN * 2 + 2); i++) D[i] = 1e18;
    priority_queue<pair<long long, int>, vector<pair<long long, int>>,
                   greater<pair<long long, int>>>
        que;
    que.push(make_pair(0, (v + PA) << 1));
    D[(v + PA) << 1] = 0;
    while (que.size()) {
      auto p = que.top();
      que.pop();
      int from = p.second;
      if (D[from] != p.first) continue;
      for (int ind = Ehe[from]; ind; ind = Ene[ind]) {
        int to = Eto[ind];
        long long d = D[from] + Eco[ind];
        if (D[to] > d) {
          D[to] = d;
          que.push(make_pair(d, to));
        }
      }
    }
  }
  long long dist(int v) { return D[(v + PA) << 1]; }
} Noshi;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  for (int i = 0; i < (M); i++) {
    int l, r, c;
    cin >> l >> r >> c;
    Noshi.AddE(l, r + 1, l, r + 1, c);
  }
  Noshi.dij(1);
  cout << (Noshi.dist(N)) << "\n";
  return 0;
}
