#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 123;
const int MAXN = 1e5 + 12;
const int inf = 1e9 + 7;
const long long mod = 1e9 + 7;
long long n, m, d[N];
bool vis[N], is[N];
vector<pair<long long, long long> > g[N];
void djk() {
  priority_queue<pair<long long, long long> > q;
  q.push({0, 1});
  pair<long long, long long> tmp;
  long long u, w;
  while (!q.empty()) {
    tmp = q.top();
    q.pop();
    u = tmp.second;
    w = -tmp.first;
    if (vis[u]) continue;
    vis[u] = 1;
    d[u] = w;
    if (u != 1 && !vis[u - 1] && is[u]) q.push({-w, u - 1});
    for (int i = 0; i < g[u].size(); i++)
      if (!vis[g[u][i].first]) q.push({-w - g[u][i].second, g[u][i].first});
  }
}
int main() {
  cin >> n >> m;
  long long x, y, z;
  memset(is, 1, sizeof(is));
  for (int i = 1; i <= m; i++) {
    cin >> x >> y >> z;
    g[x].push_back({y, z});
    is[y + 1] = is[x] = 0;
  }
  memset(d, -1, sizeof(d));
  djk();
  cout << d[n];
  return 0;
}
