import numpy as np

n, m = map(int, input().split())
edge_l = []
edge_r = []
edge_c = []
for _ in range(m):
  l, r, c = map(int, input().split())
  edge_l.append(l - 1)
  edge_r.append(r - 1)
  edge_c.append(c)
l = np.array(edge_l, dtype=np.int)
r = np.array(edge_r, dtype=np.int)
c = np.array(edge_c, dtype=np.int)

dp = np.ones(n, dtype=np.int) * (c.sum() + 1)
dp[0] = 0
flag = True
for i in range(1, n):
  use = (l < i) * (r >= i)
  if np.all(~use):
    flag = False
    break
  dp[i] = np.min(dp[l[use]] + c[use])
  
if flag:
  print(dp[-1])
else:
  print(-1)