import sys



INF = 10 ** 15



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

abc = list(map(int, sys.stdin.read().split()))

abc = list(zip(*[abc] * 3))



def main():

    dist = [INF] * n

    dist[0] = 0

    for _ in range(n - 1):

        for a, b, c in abc:

            a -= 1; b -= 1; c = -c

            if dist[a] == INF:

                continue

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



    res = dist[n-1]



    for _ in range(n - 1):

        for a, b, c in abc:

            a -= 1; b -= 1; c = -c

            if dist[a] == INF:

                continue

            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()))

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 = 10**15
n, m = list(map(int, sys.stdin.readline().split()))
abc = list(map(int, sys.stdin.read().split()))
abc = list(zip(*[abc] * 3))


def main():
    dist = [INF] * n
    dist[0] = 0
    for _ in range(n - 1):
        for a, b, c in abc:
            a -= 1
            b -= 1
            c = -c
            if dist[a] == INF:
                continue
            dist[b] = min(dist[b], dist[a] + c)
    res = dist[n - 1]
    for _ in range(n - 1):
        for a, b, c in abc:
            a -= 1
            b -= 1
            c = -c
            if dist[a] == INF:
                continue
            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()))
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)

-INF = 10**15 +inf = float("inf") -abc = list(map(int, sys.stdin.read().split())) -abc = list(zip(*[abc] * 3)) +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)) -    dist = [INF] * n +    dist = [inf] * n -            a -= 1 -            b -= 1 -            c = -c -            if dist[a] == INF: -                continue -    for _ in range(n - 1): +    for _ in range(n): -            a -= 1 -            b -= 1 -            c = -c -            if dist[a] == INF: -                continue