#include<bits/stdc++.h>

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define ALL(x) x.begin(),x.end()
#define EPS (1e-8)
#define equals(a,b) (fabs((a)-(b))<EPS)

using namespace std;

bool debug = 0;

typedef long long ll;

bool LT(double a,double b) { return !equals(a,b) && a < b; }
bool LTE(double a,double b) { return equals(a,b) || a < b; }


#define XX 100030
class SegmentTree {
  const ll inf = 1e18;
  int n, n0;
  ll max_v[4*XX], smax_v[4*XX], max_c[4*XX];

  ll ladd[4*XX]; // 区間加算クエリにおけるlazy tag
  ll len[4*XX];  // ノードの区間に含まれる要素の数

  ll sum_a[4*XX]; // 最大値の総和
  ll sum_b[4*XX]; // 非最大値の総和

  void update_node_max(int k, ll x) {
    // 最大値の総和だけ加算
    sum_a[k] += (x - max_v[k]) * max_c[k];

    max_v[k] = x;
  }

  void addall(int k, ll x) {
    max_v[k] += x; smax_v[k] += x;

    // 最大値の総和・非最大値の総和それぞれに加算
    sum_a[k] += x * max_c[k];
    sum_b[k] += x * (len[k] - max_c[k]);

    ladd[k] += x;
  }

  void push(int k) {
    if(ladd[k]) {
      addall(2*k+1, ladd[k]);
      addall(2*k+2, ladd[k]);
      ladd[k] = 0;
    }

    if(max_v[k] < max_v[2*k+1]) {
      update_node_max(2*k+1, max_v[k]);
    }
    if(max_v[k] < max_v[2*k+2]) {
      update_node_max(2*k+2, max_v[k]);
    }
  }

  void update(int k) {
    // 最大値の総和と非最大値の総和を子ノードから更新
    sum_b[k] = sum_b[2*k+1] + sum_b[2*k+2];

    if(max_v[2*k+1] < max_v[2*k+2]) {
      max_v[k] = max_v[2*k+2];
      max_c[k] = max_c[2*k+2];
      smax_v[k] = max(max_v[2*k+1], smax_v[2*k+2]);

      sum_a[k] = sum_a[2*k+2];
      sum_b[k] += sum_a[2*k+1];
    } else if(max_v[2*k+1] > max_v[2*k+2]) {
      max_v[k] = max_v[2*k+1];
      max_c[k] = max_c[2*k+1];
      smax_v[k] = max(smax_v[2*k+1], max_v[2*k+2]);

      sum_a[k] = sum_a[2*k+1];
      sum_b[k] += sum_a[2*k+2];
    } else {
      max_v[k] = max_v[2*k+1];
      max_c[k] = max_c[2*k+1] + max_c[2*k+2];
      smax_v[k] = max(smax_v[2*k+1], smax_v[2*k+2]);

      sum_a[k] = sum_a[2*k+1] + sum_a[2*k+2];
    }
  }

  void _update_min(ll x, int a, int b, int k, int l, int r) {
    if(b <= l || r <= a || max_v[k] <= x) {
      return;
    }
    if(a <= l && r <= b && smax_v[k] < x) {
      update_node_max(k, x);
      return;
    }

    push(k);
    _update_min(x, a, b, 2*k+1, l, (l+r)/2);
    _update_min(x, a, b, 2*k+2, (l+r)/2, r);
    update(k);
  }

  ll _query_max(int a, int b, int k, int l, int r) {
    if(b <= l || r <= a) {
      return 0;
    }
    if(a <= l && r <= b) {
      return max_v[k];
    }
    push(k);
    ll lv = _query_max(a, b, 2*k+1, l, (l+r)/2);
    ll rv = _query_max(a, b, 2*k+2, (l+r)/2, r);
    return max(lv, rv);
  }

  ll _query_sum(int a, int b, int k, int l, int r) {
    if(b <= l || r <= a) {
      return 0;
    }
    if(a <= l && r <= b) {
      // 最大値の総和・非最大値の総和を合わせる
      return sum_a[k] + sum_b[k];
    }
    push(k);
    ll lv = _query_sum(a, b, 2*k+1, l, (l+r)/2);
    ll rv = _query_sum(a, b, 2*k+2, (l+r)/2, r);
    return lv + rv;
  }

public:

  SegmentTree(){}
  void my_init(int _nn, ll *a) {
    n = _nn;
    n0 = 1;
    while(n0 < n) n0 <<= 1;

    len[0] = n0;
    for(int i=0; i<n0-1; ++i) len[2*i+1] = len[2*i+2] = (len[i] >> 1);

    for(int i=0; i<n; ++i) {
      max_v[n0-1+i] = sum_a[n0-1+i] = a[i];
      smax_v[n0-1+i] = -inf; sum_b[n0-1+i] = 0;
      max_c[n0-1+i] = 1;
    }

    for(int i=n; i<n0; ++i) {
      max_v[n0-1+i] = smax_v[n0-1+i] = -inf;
      sum_a[n0-1+i] = sum_b[n0-1+i] = max_c[n0-1+i] = 0;
    }
    for(int i=n0-2; i>=0; i--) update(i);
  }

  void update_min(int a, int b, ll x) {
    return _update_min(x, a, b, 0, 0, n0);
  }

  ll query_max(int a, int b) {
    return _query_max(a, b, 0, 0, n0);
  }

  ll query_sum(int a, int b) {
    return _query_sum(a, b, 0, 0, n0);
  }
};


#define MAX 100010
int N,M,L[MAX],R[MAX],C[MAX];
//ll mini[MAX];


struct Edge {
  int src, dst;
  ll cost;
  bool operator < ( const Edge &e ) const {
    if( src != e.src ) return src < e.src;
    return cost < e.cost;
  }
};



#define INF 1e18
SegmentTree seg;
ll tmp[MAX];

void compute() {
  {
    rep(i,N+1) tmp[i] = INF;
    seg.my_init(N,tmp);
    seg.update_min(0,1,0);
  }
  
  deque<Edge> edges;
  rep(i,M) edges.push_back((Edge){L[i],R[i],C[i]});
  sort(ALL(edges));

  while( !edges.empty() ) {
    Edge &e = edges.front(); edges.pop_front();
    ll mini = INF;
    if( e.src == 0 ) mini = 0;
    else mini = seg.query_max(e.src,e.src+1);
    if( debug ) {
      puts("");
      cout << "dp info---" << endl;
      rep(i,N) {
	cout << i << "-th : " << seg.query_max(i,i+1) << endl;
      }
      cout << "---" << endl;
      cout << "edge = " << e.src << "," << e.dst << ", cost = " << e.cost << endl;
      cout << "mini = " << mini << endl;
    }
    if( mini == INF ) {
      puts("-1");
      return;
    }
    if( debug ) {
      cout << "update [" << e.src << "," << e.dst << "] = " << mini+e.cost << endl;
    }
    seg.update_min(e.src,e.dst+1,mini+e.cost);
  }
  ll ans = seg.query_max(N-1,N);
  if( ans == INF ) puts("-1");
  else cout << ans << endl;
}


int main() {

  cin >> N >> M;
  rep(i,M) {
    cin >> L[i] >> R[i] >> C[i];
    --L[i], --R[i];
  }
  compute();
  return 0;
}


Measured memory_bytes: 23424