# coding: utf-8

# Your code here!



def Bellman_Ford(g,start):

    n = len(g)    

    dist = [float("inf")]*n

    dist[start] = 0

    a0 = float("inf")

    negative = [False]*n

    for i in range((2*n)):

        updated = False

        for v in range(n):

            for to, cost in g[v]:

                if negative[v]: negative[to] = True

                if dist[to] <= dist[v] + cost: continue

                dist[to] = dist[v] + cost

                updated = True

                if i >= n:

                    negative[to] = True

        if not updated: break

    if negative[-1]: return None, False

    return dist, True

 



import sys

sys.setrecursionlimit(10**6)

readline = sys.stdin.readline #文字列入力のときは注意



n,m,p = [int(i) for i in readline().split()]

g = [[] for _ in range(n)]

for i in range(m):

    a,b,c = [int(i) for i in readline().split()]

    g[a-1].append((b-1,-c+p))

#    g[b-1].append((a-1,c))



dist, TF = Bellman_Ford(g, 0)



if TF: print((max(-dist[-1],0)))

else: print((-1))





"""

Bellman-Ford

始点と終点が決められているとき、

経由する閉路のみを確認する必要がある。

"""

def Bellman_Ford2(g,start,goal):

    n = len(g)    

    dist = [float("inf")]*n

    dist[start] = 0

    a0 = float("inf")

    for i in range(2*n):

        updated = False

        for v in range(n):

            for to, cost in g[v]:

                if dist[to] <= dist[v] + cost: continue

                if i < n:

                    dist[to] = dist[v] + cost

                else:

                    dist[to] = -float("inf")

                updated = True

        if not updated: break

    if dist[goal] == -float("inf"): return None, False

#    if negative[-1]: return None, False

    return dist, True

 



import sys

sys.setrecursionlimit(10**6)

readline = sys.stdin.readline #文字列入力のときは注意



n,m,p = [int(i) for i in readline().split()]

g = [[] for _ in range(n)]

for i in range(m):

    a,b,c = [int(i) for i in readline().split()]

    g[a-1].append((b-1,-c+p))

#    g[b-1].append((a-1,c))



dist, TF = Bellman_Ford2(g,0,-1)



if TF: print((max(-dist[-1],0)))

else: print((-1))
# coding: utf-8
# Your code here!
def Bellman_Ford(g, start):
    n = len(g)
    dist = [float("inf")] * n
    dist[start] = 0
    a0 = float("inf")
    negative = [False] * n
    for i in range((2 * n)):
        updated = False
        for v in range(n):
            for to, cost in g[v]:
                if negative[v]:
                    negative[to] = True
                if dist[to] <= dist[v] + cost:
                    continue
                dist[to] = dist[v] + cost
                updated = True
                if i >= n:
                    negative[to] = True
        if not updated:
            break
    if negative[-1]:
        return None, False
    return dist, True


import sys

sys.setrecursionlimit(10**6)
readline = sys.stdin.readline  # 文字列入力のときは注意
n, m, p = [int(i) for i in readline().split()]
g = [[] for _ in range(n)]
for i in range(m):
    a, b, c = [int(i) for i in readline().split()]
    g[a - 1].append((b - 1, -c + p))
#    g[b-1].append((a-1,c))
dist, TF = Bellman_Ford(g, 0)
if TF:
    print((max(-dist[-1], 0)))
else:
    print((-1))

"""
Bellman-Ford
始点と終点が決められているとき、
経由する閉路のみを確認する必要がある。
"""


def Bellman_Ford2(g, start, goal):
    n = len(g)
    dist = [float("inf")] * n
    dist[start] = 0
    a0 = float("inf")
    for i in range(2 * n):
        updated = False
        for v in range(n):
            for to, cost in g[v]:
                if dist[to] <= dist[v] + cost:
                    continue
                if i < n:
                    dist[to] = dist[v] + cost
                else:
                    dist[to] = -float("inf")
                updated = True
        if not updated:
            break
    if dist[goal] == -float("inf"):
        return None, False
    #    if negative[-1]: return None, False
    return dist, True


import sys

sys.setrecursionlimit(10**6)
readline = sys.stdin.readline  # 文字列入力のときは注意
n, m, p = [int(i) for i in readline().split()]
g = [[] for _ in range(n)]
for i in range(m):
    a, b, c = [int(i) for i in readline().split()]
    g[a - 1].append((b - 1, -c + p))
#    g[b-1].append((a-1,c))
dist, TF = Bellman_Ford2(g, 0, -1)
if TF:
    print((max(-dist[-1], 0)))
else:
    print((-1))

-# coding: utf-8 -# Your code here! -def Bellman_Ford(g, start): +""" +Bellman-Ford +始点と終点が決められているとき、 +経由する閉路のみを確認する必要がある。 +""" + + +def Bellman_Ford2(g, start, goal): -    negative = [False] * n -    for i in range((2 * n)): +    for i in range(2 * n): -                if negative[v]: -                    negative[to] = True -                dist[to] = dist[v] + cost +                if i < n: +                    dist[to] = dist[v] + cost +                else: +                    dist[to] = -float("inf") -                if i >= n: -                    negative[to] = True -    if negative[-1]: +    if dist[goal] == -float("inf"): +    #    if negative[-1]: return None, False -dist, TF = Bellman_Ford(g, 0) +dist, TF = Bellman_Ford2(g, 0, -1)