import sys



inf = float('inf')



n, m = list(map(int, sys.stdin.readline().split()))

a = []

b = []

c = []

for _ in range(m):

    ai, bi, ci = list(map(int, sys.stdin.readline().split()))

    a.append(ai - 1)

    b.append(bi - 1)

    c.append(-ci)

abc = list(zip(a, b, c))



def main():

    dist = [inf] * n

    dist[0] = 0

    for _ in range(n-1):

        for a, b, c in abc:

            dist[b] = min(dist[b], dist[a] + c)



    res = dist[n-1]



    for _ in range(n):

        for a, b, c in abc:

            dist[b] = min(dist[b], dist[a] + c)



    if dist[n-1] == res:

        return -res

    else:

        return 'inf'



if __name__ == '__main__':

    ans = main()

    print(ans)
import sys



inf = float('inf')



n, m = list(map(int, sys.stdin.readline().split()))

abc = []

for _ in range(m):

    a, b, c = list(map(int, sys.stdin.readline().split()))

    abc.append((a-1, b-1, -c))



def main():

    dist = [inf] * n

    dist[0] = 0

    for _ in range(n-1):

        for a, b, c in abc:

            dist[b] = min(dist[b], dist[a] + c)



    for _ in range(n):

        for a, b, c in abc:

            if dist[a] + c < dist[b]:

                dist[b] = -inf



    return -dist[n-1]



if __name__ == '__main__':

    ans = main()

    print(ans)
import sys

inf = float("inf")
n, m = list(map(int, sys.stdin.readline().split()))
a = []
b = []
c = []
for _ in range(m):
    ai, bi, ci = list(map(int, sys.stdin.readline().split()))
    a.append(ai - 1)
    b.append(bi - 1)
    c.append(-ci)
abc = list(zip(a, b, c))


def main():
    dist = [inf] * n
    dist[0] = 0
    for _ in range(n - 1):
        for a, b, c in abc:
            dist[b] = min(dist[b], dist[a] + c)
    res = dist[n - 1]
    for _ in range(n):
        for a, b, c in abc:
            dist[b] = min(dist[b], dist[a] + c)
    if dist[n - 1] == res:
        return -res
    else:
        return "inf"


if __name__ == "__main__":
    ans = main()
    print(ans)

import sys

inf = float("inf")
n, m = list(map(int, sys.stdin.readline().split()))
abc = []
for _ in range(m):
    a, b, c = list(map(int, sys.stdin.readline().split()))
    abc.append((a - 1, b - 1, -c))


def main():
    dist = [inf] * n
    dist[0] = 0
    for _ in range(n - 1):
        for a, b, c in abc:
            dist[b] = min(dist[b], dist[a] + c)
    for _ in range(n):
        for a, b, c in abc:
            if dist[a] + c < dist[b]:
                dist[b] = -inf
    return -dist[n - 1]


if __name__ == "__main__":
    ans = main()
    print(ans)

-a = [] -b = [] -c = [] +abc = [] -    ai, bi, ci = list(map(int, sys.stdin.readline().split())) -    a.append(ai - 1) -    b.append(bi - 1) -    c.append(-ci) -abc = list(zip(a, b, c)) +    a, b, c = list(map(int, sys.stdin.readline().split())) +    abc.append((a - 1, b - 1, -c)) -    res = dist[n - 1] -            dist[b] = min(dist[b], dist[a] + c) -    if dist[n - 1] == res: -        return -res -    else: -        return "inf" +            if dist[a] + c < dist[b]: +                dist[b] = -inf +    return -dist[n - 1]