n, m = map(int, input().split())
lrc = []
for i in range(m):
    lrc.append(list(map(int, input().split())))
lrc.sort(key = lambda x: x[1])
lrc.sort()
dis = [float("inf")] * n
dis[0] = 0
for i in range(m):
    l = lrc[i][0]
    r = lrc[i][1]
    c = lrc[i][2]
    for j in range(l + 1, r + 1):
        dis[j - 1] = min(dis[j - 1], dis[l - 1] + c)
if dis[n - 1] == float("inf"):
    print(-1)
else:
    print(dis[n - 1])