#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M, l, r, c;
  cin >> N >> M;
  vector<int> dis(N, -1);
  vector<vector<int>> mat;
  priority_queue<pair<int, int>> Q;
  vector<pair<int, int>> acts;
  for (int i = 0; i < N; i++) {
    mat.emplace_back(vector<int>(N, 0));
  }
  int p = 0;
  for (int i = 0; i < M; i++) {
    cin >> l >> r >> c;
    int cost = 0;
    for (int j = l; j < r; j++) {
      dis[j] = (dis[j] < 0 ? max(0, dis[l - 1]) + c
                           : min(dis[j], c + max(0, dis[l])));
    }
    p = r - 1;
  }
  int ans = dis.back();
  bool f = false;
  for (int i = 0; i < N; i++) {
    cerr << dis[i] << endl;
  }
  cout << ans << endl;
  return 0;
}
