n, m = [int(x) for x in input().split(' ')]

x = []
for i in range(m):
    x.append([int(x) for x in input().split(' ')])

data = [10 ** 9] * (n + 1)
data[1] = 0

for l, r, c in sorted(x):
    for j in range(l, r):
        for k in range(j + 1, r + 1):
            v = data[j] + c
            if v < data[k]:
                data[k] = v

if data[n] == 10 ** 9:
    print(-1)
else:
    print(data[n])
