#![allow(unused_imports, unused_macros, dead_code)]

macro_rules! min {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| min!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = min!($($ys),*);
        if $x < t { $x } else { t }
    }}
}
macro_rules! max {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| max!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = max!($($ys),*);
        if $x > t { $x } else { t }
    }}
}


macro_rules! ewriteln {
    ($($args:expr),*) => { let _ = writeln!(&mut std::io::stderr(), $($args),*); };
}
macro_rules! trace {
    ($x:expr) => { ewriteln!(">>> {} = {:?}", stringify!($x), $x) };
    ($($xs:expr),*) => { trace!(($($xs),*)) }
}
macro_rules! put {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        if let Some(x) = it.next() { print!("{}", x); }
        for x in it { print!(" {}", x); }
        println!("");
    }};
    ($x:expr) => { println!("{}", $x) };
    ($x:expr, $($xs:expr),*) => { print!("{} ", $x); put!($($xs),*) }
}

const M: i64 = 1_000_000_007;
use std::u64;
use std::ops::{Range, Index};
use std::cmp::{ min, max };

struct RMQ {
    size: usize, len: usize,
    heap_min: Vec<u64>,
    lefts: Vec<usize>, rights: Vec<usize>
}
    const INF: u64 = 1_000_000_000_000;

impl RMQ {

    fn new(n: usize) -> RMQ {
        let size = RMQ::alignment(n);
        let lefts = (0..size).map(|i| RMQ::of_left(i, size/2)).collect();
        let rights = (0..size).map(|i| RMQ::of_right(i, size/2)).collect();
        let mut heap_min = vec![0; size];
        for i in 0..n { heap_min[i + size/2] = INF }
        for i in (0..size/2).rev() { heap_min[i] = min(heap_min[i*2+1], heap_min[i*2+2]); }
        RMQ {size: size, len: n, heap_min: heap_min, lefts: lefts, rights: rights}
    }

    fn len(&self) -> usize {
        self.len
    }

    fn alignment(n: usize) -> usize {
        let mut m = 1;
        while n > m { m <<= 1; }
        m * 2 - 1
    }

    fn of_left(idx: usize, base: usize) -> usize {
        let mut i = idx; while i < base { i = i * 2 + 1; }
        i - base
    }

    fn of_right(idx: usize, base: usize) -> usize {
        let mut i = idx; while i < base { i = i * 2 + 2; }
        i - base + 1
    }

    fn min(&self, range: Range<usize>) -> u64 {
        if range.end == 0 || range.start + 1 > range.end {
            return INF;
        }
        if range.start + 1 == range.end {
            return self.heap_min[self.size / 2 + range.start]
        }
        let left = range.start;
        let right = range.end;
        let mut i = self.size / 2 + left;
        while i > 0 {
            let p = (i - 1) / 2;
            if self.lefts[p] == range.start && self.rights[p] <= range.end {
                i = p;
            } else {
                break
            }
        }
        min(self.heap_min[i], self.min(self.rights[i]..right))
    }

    // [idx] <- x
    fn update(&mut self, idx: usize, x: u64) {
        let mut i = idx + self.size/2;
        self.heap_min[i] = x;
        loop {
            i = (i - 1) / 2;
            if i == 0 { break }
            self.heap_min[i] = min(self.heap_min[i*2+1], self.heap_min[i*2+2]);
        }
    }

    // [idx] <- [idx] + x
    fn add(&mut self, idx: usize, x: u64) {
        self.update(idx, self[idx] + x);
    }

    fn to_vec(&self) -> Vec<u64> {
        (0..self.len()).map(|i| self[i]).collect()
    }
}

impl Index<usize> for RMQ {
    type Output = u64;
    fn index(&self, i: usize) -> &u64 {
        &self.heap_min[i + self.size / 2]
    }
}

fn main() {
    let mut sc = Scanner::new();
    let n: usize = sc.cin();
    let m: usize = sc.cin();
    let mut qs = vec![];
    for _ in 0..m {
        let l = sc.cin::<usize>() - 1;
        let r = sc.cin::<usize>() - 1;
        let c: u64 = sc.cin();
        qs.push((r, l, c));
    }
    qs.sort();

    let mut rmq = RMQ::new(n + 10);
    rmq.update(0, 0);
    for &(r, l, c) in qs.iter() {
        // trace!(r, l, c);
        let mn = rmq.min(l..r+1);
        // trace!(mn);
        if rmq[r] > mn + c {
            rmq.update(r, mn + c);
        }
    }
    if rmq[n - 1] == INF {
        put!(-1);
    } else {
        put!(rmq[n - 1]);
    }
}

use std::io::{self, Write};
use std::str::FromStr;
use std::collections::VecDeque;

struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
impl Scanner {
    fn new() -> Self { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn cin<T: FromStr>(&mut self) -> T {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
        self.buffer.pop_front().unwrap().parse::<T>().ok().unwrap()
    }
    fn chars(&mut self) -> Vec<char> { self.cin::<String>().chars().collect() }
    fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T> { (0..n).map(|_| self.cin()).collect() }
}
