#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;
long long dijkstra(int N, int s, int g, vector<vector<long long>> cost,
                   vector<vector<int>> adj) {
  vector<long long> d(N + 1, INF);
  vector<bool> used(N + 1, false);
  vector<int> back(N + 1, -1);
  fill(d.begin(), d.end(), INF);
  fill(used.begin(), used.end(), false);
  fill(back.begin(), back.end(), -1);
  d[s] = 0;
  priority_queue<pair<int, int>, vector<pair<int, int>>,
                 greater<pair<int, int>>>
      PQ;
  PQ.push(make_pair(s, 0));
  used[s] = true;
  while (!PQ.empty()) {
    pair<int, int> f = PQ.top();
    PQ.pop();
    int u = f.first;
    used[u] = true;
    if (d[u] < f.second) continue;
    for (int j = 0; j < adj[u].size(); j++) {
      int v = adj[u][j];
      if (used[v] == true) continue;
      if (d[v] > d[u] + cost[u][v]) {
        d[v] = d[u] + cost[u][v];
        PQ.push(make_pair(v, d[v]));
        back[u] = v;
      }
    }
  }
  return d[g];
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  vector<int> L, R, C;
  int l, r, c;
  for (int i = 0; i < M; i++) {
    cin >> l >> r >> c;
    L.push_back(l);
    R.push_back(r);
    C.push_back(c);
  }
  vector<vector<long long>> path(N + 1, vector<long long>(N + 1, INF));
  vector<vector<int>> adj(N + 1);
  for (int i = N; i > 0; i--) {
    path[i][i - 1] = 0;
    adj[i].push_back(i - 1);
  }
  for (int i = 0; i < (int)(M); i++) {
    path[L[i]][R[i]] = C[i];
    adj[L[i]].push_back(R[i]);
  }
  long long ans = dijkstra(N, 1, N, path, adj);
  if (ans == INF) {
    cout << -1 << "\n";
  } else {
    cout << ans << "\n";
  }
  return 0;
}
