def resolve():

    n, m = list(map(int, input().split()))

    a = [list(map(int, input().split())) for i in range(m)]

    a = [[x, y, -z] for x, y, z in a]

    print((BF(a, n, 1)[-1]))





def BF(p, n, s):

    inf = float("inf")

    d = [inf for i in range(n)]

    d[s-1] = 0

    for i in range(n+1):

        for e in p:

            if e[0] != inf and d[e[1]-1] > d[e[0]-1]+e[2]:

                d[e[1]-1] = d[e[0]-1] + e[2]

        if i == n-1:

            t = d[-1]

        if i == n and t != d[-1]:

            return [0, 'inf']

    return list([-x for x in d])





if __name__ == "__main__":

    resolve()
def BellmanFord():

    def BF(s, n, edge, inf=float("inf")):

        d = [inf for i in range(n)]

        d[s] = 0

        for i in range(n):

            for before, after, dist in edge:

                if before != inf:

                    d[after] = min(d[after], d[before] + dist)

            if i == n - 2:

                t = d[:]

            elif i == n - 1:

                for i, j in enumerate(d):

                    if j != t[i]:

                        d[i] = -inf

        return list([-x for x in d])

    n, m = list(map(int, input().split()))

    inf = 10 ** 20

    edge = [list(map(int, input().split())) for i in range(m)]

    edge = [[x - 1, y - 1, -z] for x, y, z in edge]

    l = BF(0, n, edge)

    print((l[-1] if l[-1] < inf else "inf"))

BellmanFord()
def resolve():
    n, m = list(map(int, input().split()))
    a = [list(map(int, input().split())) for i in range(m)]
    a = [[x, y, -z] for x, y, z in a]
    print((BF(a, n, 1)[-1]))


def BF(p, n, s):
    inf = float("inf")
    d = [inf for i in range(n)]
    d[s - 1] = 0
    for i in range(n + 1):
        for e in p:
            if e[0] != inf and d[e[1] - 1] > d[e[0] - 1] + e[2]:
                d[e[1] - 1] = d[e[0] - 1] + e[2]
        if i == n - 1:
            t = d[-1]
        if i == n and t != d[-1]:
            return [0, "inf"]
    return list([-x for x in d])


if __name__ == "__main__":
    resolve()

def BellmanFord():
    def BF(s, n, edge, inf=float("inf")):
        d = [inf for i in range(n)]
        d[s] = 0
        for i in range(n):
            for before, after, dist in edge:
                if before != inf:
                    d[after] = min(d[after], d[before] + dist)
            if i == n - 2:
                t = d[:]
            elif i == n - 1:
                for i, j in enumerate(d):
                    if j != t[i]:
                        d[i] = -inf
        return list([-x for x in d])

    n, m = list(map(int, input().split()))
    inf = 10**20
    edge = [list(map(int, input().split())) for i in range(m)]
    edge = [[x - 1, y - 1, -z] for x, y, z in edge]
    l = BF(0, n, edge)
    print((l[-1] if l[-1] < inf else "inf"))


BellmanFord()

-def resolve(): +def BellmanFord(): +    def BF(s, n, edge, inf=float("inf")): +        d = [inf for i in range(n)] +        d[s] = 0 +        for i in range(n): +            for before, after, dist in edge: +                if before != inf: +                    d[after] = min(d[after], d[before] + dist) +            if i == n - 2: +                t = d[:] +            elif i == n - 1: +                for i, j in enumerate(d): +                    if j != t[i]: +                        d[i] = -inf +        return list([-x for x in d]) + -    a = [list(map(int, input().split())) for i in range(m)] -    a = [[x, y, -z] for x, y, z in a] -    print((BF(a, n, 1)[-1])) +    inf = 10**20 +    edge = [list(map(int, input().split())) for i in range(m)] +    edge = [[x - 1, y - 1, -z] for x, y, z in edge] +    l = BF(0, n, edge) +    print((l[-1] if l[-1] < inf else "inf")) -def BF(p, n, s): -    inf = float("inf") -    d = [inf for i in range(n)] -    d[s - 1] = 0 -    for i in range(n + 1): -        for e in p: -            if e[0] != inf and d[e[1] - 1] > d[e[0] - 1] + e[2]: -                d[e[1] - 1] = d[e[0] - 1] + e[2] -        if i == n - 1: -            t = d[-1] -        if i == n and t != d[-1]: -            return [0, "inf"] -    return list([-x for x in d]) - - -if __name__ == "__main__": -    resolve() +BellmanFord()