"""解説を見てから解いたコード"""

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

edges = []

for _ in range(M):

    a, b, c = list(map(int, input().split()))

    edges.append((a, b, c-P))



INF = float('inf')



coin_map = [-INF] * (N+1)

coin_map[1] = 0



for i in range(2*N):

    for a, b, c in edges:

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

            coin_map[b] = coin_map[a] + c

            if i >= N:

                coin_map[b] = INF



    if i == N - 1:

        ans = coin_map[N]



if ans != coin_map[N]:

    print((-1))

else:

    print((max(0, coin_map[N])))





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

A=[]

for i in range(m):

    a,b,c=list(map(int,input().split()))

    A.append((a,b,c-p))



def BellmanFord(edges,num_v,source):

    #グラフの初期化

    inf=float("inf")

    dist=[-inf for i in range(num_v)]

    dist[source-1]=0

  

    #辺の緩和

    buf=0

    for i in range(num_v*2):

        for edge in edges:

            if dist[edge[1]-1] < dist[edge[0]-1] + edge[2]:

                dist[edge[1]-1] = dist[edge[0]-1] + edge[2]

                if i>=num_v:

                    dist[edge[1]-1] =inf

        if i==num_v-1:

            buf=dist[-1]

    if dist[-1]!=buf or dist[-1]==-inf:

        return -1

    return max(dist[-1],0)



x=BellmanFord(A,n,1)

print(x)
"""解説を見てから解いたコード"""
N, M, P = list(map(int, input().split()))
edges = []
for _ in range(M):
    a, b, c = list(map(int, input().split()))
    edges.append((a, b, c - P))
INF = float("inf")
coin_map = [-INF] * (N + 1)
coin_map[1] = 0
for i in range(2 * N):
    for a, b, c in edges:
        if coin_map[b] < coin_map[a] + c:
            coin_map[b] = coin_map[a] + c
            if i >= N:
                coin_map[b] = INF
    if i == N - 1:
        ans = coin_map[N]
if ans != coin_map[N]:
    print((-1))
else:
    print((max(0, coin_map[N])))

n, m, p = list(map(int, input().split()))
A = []
for i in range(m):
    a, b, c = list(map(int, input().split()))
    A.append((a, b, c - p))


def BellmanFord(edges, num_v, source):
    # グラフの初期化
    inf = float("inf")
    dist = [-inf for i in range(num_v)]
    dist[source - 1] = 0
    # 辺の緩和
    buf = 0
    for i in range(num_v * 2):
        for edge in edges:
            if dist[edge[1] - 1] < dist[edge[0] - 1] + edge[2]:
                dist[edge[1] - 1] = dist[edge[0] - 1] + edge[2]
                if i >= num_v:
                    dist[edge[1] - 1] = inf
        if i == num_v - 1:
            buf = dist[-1]
    if dist[-1] != buf or dist[-1] == -inf:
        return -1
    return max(dist[-1], 0)


x = BellmanFord(A, n, 1)
print(x)

-"""解説を見てから解いたコード""" -N, M, P = list(map(int, input().split())) -edges = [] -for _ in range(M): +n, m, p = list(map(int, input().split())) +A = [] +for i in range(m): -    edges.append((a, b, c - P)) -INF = float("inf") -coin_map = [-INF] * (N + 1) -coin_map[1] = 0 -for i in range(2 * N): -    for a, b, c in edges: -        if coin_map[b] < coin_map[a] + c: -            coin_map[b] = coin_map[a] + c -            if i >= N: -                coin_map[b] = INF -    if i == N - 1: -        ans = coin_map[N] -if ans != coin_map[N]: -    print((-1)) -else: -    print((max(0, coin_map[N]))) +    A.append((a, b, c - p)) + + +def BellmanFord(edges, num_v, source): +    # グラフの初期化 +    inf = float("inf") +    dist = [-inf for i in range(num_v)] +    dist[source - 1] = 0 +    # 辺の緩和 +    buf = 0 +    for i in range(num_v * 2): +        for edge in edges: +            if dist[edge[1] - 1] < dist[edge[0] - 1] + edge[2]: +                dist[edge[1] - 1] = dist[edge[0] - 1] + edge[2] +                if i >= num_v: +                    dist[edge[1] - 1] = inf +        if i == num_v - 1: +            buf = dist[-1] +    if dist[-1] != buf or dist[-1] == -inf: +        return -1 +    return max(dist[-1], 0) + + +x = BellmanFord(A, n, 1) +print(x)