import std.stdio;
import std.c.stdio;
import std.range;
import std.array;
import std.functional;
import std.algorithm;
import std.conv;
import std.container;
import std.math;
import std.numeric;
import std.string;
import std.c.string;
import std.regex;
import std.typecons;

void main() {
    int n, m;
    scanf("%d %d\n", &n, &m);
    int[][] g = new int[][](n, n);
    foreach (i; 0 .. m) {
        int a, b, c;
        scanf("%d %d %d\n", &a, &b, &c);
        g[a][b] = c;
    }
    int[] cache = new int[n];
    cache[] = -1;
    int dfs(int v) {
        if (v == n - 1) return 0;
        if (cache[v] >= 0) return cache[v];
        int ret = 0;
        foreach (i; 0 .. n) {
            if (v == i) continue;
            if (g[v][i] == 0) continue;
            ret = max(ret, g[v][i] + dfs(i));
        }
        return cache[v] = ret;
    }
    dfs(0).writeln;
}