#include <bits/stdc++.h>
using namespace std;
const long long int inf = 9223372036854775807;
int n, s;
int a, b, c;
long long int m[10000][10000];
long long int dis[10000];
int main() {
  cin >> n >> s;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      m[i][j] = inf;
      m[i][i] = 0;
    }
  }
  for (int i = 1; i <= s; i++) {
    cin >> a >> b >> c;
    for (int p = a; p <= b - 1; p++) {
      for (int k = p + 1; k <= b; k++) {
        if (m[p][k] > c) {
          m[p][k] = c;
        }
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    dis[i] = m[1][i];
  }
  int num;
  int s = 2;
  while (s <= n) {
    for (int i = s; i <= n; i++) {
      long long int min = inf;
      if (dis[i] < min) {
        min = dis[i];
        num = i;
      }
      for (int i = 1; i <= n; i++) {
        if ((m[num][i] != inf) && (m[num][i] != 0) &&
            (dis[i] >= dis[num] + m[num][i])) {
          dis[i] = dis[num] + m[num][i];
        }
      }
    }
    s++;
  }
  if (dis[n] == inf) {
    cout << -1 << endl;
  } else {
    cout << dis[n] << endl;
  }
  return 0;
}
