#include<iostream>
#include<vector>
#include<algorithm>
#include<tuple>
using namespace std;
#define INF 1000000000

vector<pair<pair<int,int>,int>> Graph;

struct Segtree{
  vector<int> data;
  int n;
  
  void Segtree(vector<int> v){
  	int n = 1;
    while(1<<n < v.size()) n = 2*n;
    data.resize(2*n-1);
    for(int i=0;i<2*n-1;i++) data[i] = INF;
    for(int i=0;i<n;i++) data[n+i] = v[i];
    for(int i=n-1;i>=0;i--) data[i] = min(data[2*i+1],data[2*i+2]);
  }
  
  void change(int id, int val){
  	int i = id + n - 1;
    data[i] = val;
    i = i/2;
    while(1){
    	data[i] = min(data[2*i+1],data[2*i+2]);
      	if(i==0) break;
    	i = i/2;
    }
  }
  
  int find(int a, int b,int k=0, int l=0, int r=n){
  	if(a<=l && b<=r) return data[k];
    else (l <= a || b <= r) return INF;
    else {
    	return min(find(a, b, 2*k+1, l,(l+r)/2), find(a,b, 2*k+2, (l+r)/2, r));
    }
  }
};

int main(){
  int n,m; 
  cin >> n >> m;
  vector<int> v(n); v[0]=0;
  Segtree segt(v);
  Graph g(m);
  for(int i=0;i<m;i++){
  	cin >> g[i].first.second >> g[i].first.second >> g[i].second;
  }
  sort(g.begin(), g.end());
  for(int i=0;i<m;i++){
  	int l = g[i].first.second-1, r = g[i].first.second-1 , c = g[i].second;
  	int mc = segt.find(l,r+1);
    segt.change(r, mc+d);
  }
  cout << segt.find(n-1,n) << endl;
  return 0;
}
  