#include <bits/stdc++.h>
typedef struct {
  int l, r, c;
} pathInfo;
long long solve(const int n, std::vector<pathInfo> path) {
  const int m = path.size();
  std::vector<long long> dist(n, std::numeric_limits<long long>::max());
  std::sort(path.begin(), path.end(),
            [](const pathInfo &a, const pathInfo &b) { return a.l < b.l; });
  dist[0] = 0;
  for (int i = 0; i < n - 1; i++) {
    if (dist[i] == std::numeric_limits<long long>::max()) {
      return -1;
    }
    for (int j = 0; j < m; j++) {
      if ((path[j].l <= i) && (i < path[j].r)) {
        const int last = path[j].r;
        for (int k = i + 1; k <= last; k++) {
          dist[k] = std::min(dist[k], dist[i] + path[j].c);
        }
      }
    }
  }
  return dist[n - 1];
}
int main(int argc, char *argv[]) {
  int n, m;
  std::vector<pathInfo> path;
  long long ans = -1;
  std::cin >> n >> m;
  path.resize(m);
  for (int i = 0; i < m; i++) {
    int l, r, c;
    std::cin >> l >> r >> c;
    l--;
    r--;
    path[i] = {l, r, c};
  }
  ans = solve(n, path);
  std::cout << ans << std::endl;
  return 0;
}
