N,M = list(map(int,input().split()))

ABC = [list(map(int,input().split())) for _ in [0]*M]



E = [{} for _ in [0]*N]

for a,b,c in ABC:

    E[a-1][b-1] = -c





INFTY = 10**18

d = [INFTY]*N

d[0] = 0



def update():

    done = [False]*N

    done[0] = True

    q = [0]

    qp = q.pop

    qa = q.append

    while q:

        i = qp()

        di = d[i]

        for j,c in list(E[i].items()):

            d[j] = min(d[j],d[i]+c)

            if not done[j]:

                qa(j)

                done[j] = True



for _ in range(N-1):update()

dc = d[:]

for _ in range(N):update()

if dc[-1]!=d[-1]:

    print("inf")

else:

    print((-d[-1]))
N,M = list(map(int,input().split()))

ABC = [list(map(int,input().split())) for _ in [0]*M]



E = [{} for _ in [0]*N]

Eb = [{} for _ in [0]*N]

for a,b,c in ABC:

    E[a-1][b-1] = -c

    Eb[b-1][a-1] = -c



#0 -> N-1 経路上にない頂点を除く

V1 = [False]*N

V1[0] = True

q = [0]

qp = q.pop

qa = q.append

while q:

    i = qp()

    for j in E[i]:

        if V1[j]:continue

        qa(j)

        V1[j]=True

V2 = [False]*N

V2[-1] = True

qa(N-1)

while q:

    i = qp()

    for j in Eb[i]:

        if V2[j] or not V1[j]:continue

        qa(j)

        V2[j]=True

for i in range(N):

    if V1[i] and V2[i]:continue

    for j in Eb[i]:

        E[j].pop(i)



INFTY = 10**18

d = [INFTY]*N

d[0] = 0



def update():

    done = [False]*N

    done[0] = True

    q = [0]

    qp = q.pop

    qa = q.append

    while q:

        i = qp()

        di = d[i]

        for j,c in list(E[i].items()):

            d[j] = min(d[j],d[i]+c)

            if not done[j]:

                qa(j)

                done[j] = True

                

for _ in range(N-1):update()

dc = d[:]

update()

if dc!=d:

    print("inf")

else:

    print((-d[-1]))
N, M = list(map(int, input().split()))
ABC = [list(map(int, input().split())) for _ in [0] * M]
E = [{} for _ in [0] * N]
for a, b, c in ABC:
    E[a - 1][b - 1] = -c
INFTY = 10**18
d = [INFTY] * N
d[0] = 0


def update():
    done = [False] * N
    done[0] = True
    q = [0]
    qp = q.pop
    qa = q.append
    while q:
        i = qp()
        di = d[i]
        for j, c in list(E[i].items()):
            d[j] = min(d[j], d[i] + c)
            if not done[j]:
                qa(j)
                done[j] = True


for _ in range(N - 1):
    update()
dc = d[:]
for _ in range(N):
    update()
if dc[-1] != d[-1]:
    print("inf")
else:
    print((-d[-1]))

N, M = list(map(int, input().split()))
ABC = [list(map(int, input().split())) for _ in [0] * M]
E = [{} for _ in [0] * N]
Eb = [{} for _ in [0] * N]
for a, b, c in ABC:
    E[a - 1][b - 1] = -c
    Eb[b - 1][a - 1] = -c
# 0 -> N-1 経路上にない頂点を除く
V1 = [False] * N
V1[0] = True
q = [0]
qp = q.pop
qa = q.append
while q:
    i = qp()
    for j in E[i]:
        if V1[j]:
            continue
        qa(j)
        V1[j] = True
V2 = [False] * N
V2[-1] = True
qa(N - 1)
while q:
    i = qp()
    for j in Eb[i]:
        if V2[j] or not V1[j]:
            continue
        qa(j)
        V2[j] = True
for i in range(N):
    if V1[i] and V2[i]:
        continue
    for j in Eb[i]:
        E[j].pop(i)
INFTY = 10**18
d = [INFTY] * N
d[0] = 0


def update():
    done = [False] * N
    done[0] = True
    q = [0]
    qp = q.pop
    qa = q.append
    while q:
        i = qp()
        di = d[i]
        for j, c in list(E[i].items()):
            d[j] = min(d[j], d[i] + c)
            if not done[j]:
                qa(j)
                done[j] = True


for _ in range(N - 1):
    update()
dc = d[:]
update()
if dc != d:
    print("inf")
else:
    print((-d[-1]))

+Eb = [{} for _ in [0] * N] +    Eb[b - 1][a - 1] = -c +# 0 -> N-1 経路上にない頂点を除く +V1 = [False] * N +V1[0] = True +q = [0] +qp = q.pop +qa = q.append +while q: +    i = qp() +    for j in E[i]: +        if V1[j]: +            continue +        qa(j) +        V1[j] = True +V2 = [False] * N +V2[-1] = True +qa(N - 1) +while q: +    i = qp() +    for j in Eb[i]: +        if V2[j] or not V1[j]: +            continue +        qa(j) +        V2[j] = True +for i in range(N): +    if V1[i] and V2[i]: +        continue +    for j in Eb[i]: +        E[j].pop(i) -for _ in range(N): -    update() -if dc[-1] != d[-1]: +update() +if dc != d: