from collections import deque

NegInf = -float('inf')





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

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

for i in range(m):

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

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





def bellman_ford(vst, graph, node_num, NegInf):

    costs = [NegInf] * node_num

    costs[0] = 0

    v_nows = set([vst])

    for _ in range(n):

        v_changeds = set()

        for v_from in v_nows:

            for v_to, cost in graph[v_from]:

                c2 = costs[v_from] + cost

                if c2 > costs[v_to]:

                    costs[v_to] = c2

                    v_changeds.add(v_to)

        v_nows = v_changeds







    if not v_changeds:

        return costs



    for i in v_nows:

        costs[i] = NegInf



    que = deque(v_nows)

    while que:

        v_from = que.popleft()

        for v_to, cost in graph[v_from]:

            if costs[v_to] != NegInf:

                costs[v_to] = NegInf

                que.append(v_to)

    return costs





costs = bellman_ford(0, graph, n, -float('inf'))

if costs[n-1] == NegInf:

    print((-1))

else:

    print((max(0, costs[n-1])))
from collections import defaultdict, deque, Counter

from heapq import heappush, heappop, heapify

import math

import bisect

import random

from itertools import permutations, accumulate, combinations, product

import sys

import string

from bisect import bisect_left, bisect_right

from math import factorial, ceil, floor

from functools import reduce





sys.setrecursionlimit(2147483647)

INF = 10 ** 18

def LI(): return list(map(int, sys.stdin.buffer.readline().split()))

def I(): return int(sys.stdin.buffer.readline())

def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()

def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')

def IR(n): return [I() for i in range(n)]

def LIR(n): return [LI() for i in range(n)]

def SR(n): return [S() for i in range(n)]

def LSR(n): return [LS() for i in range(n)]

def SRL(n): return [list(S()) for i in range(n)]

def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]

mod = 1000000007





n, m, p = LI()

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

for i in range(m):

    a, b, c = LI()

    G[a - 1] += [(b - 1, c - p)]





def bellman_ford(G, start=0):

    n = len(G)

    costs = [-INF] * n

    costs[0] = 0

    v_nows = set([start])

    for _ in range(n):

        v_changeds = set()

        for u in v_nows:

            for v, c in G[u]:

                if costs[u] + c > costs[v]:

                    costs[v] = costs[u] + c

                    v_changeds.add(v)

        v_nows = v_changeds

    if not v_changeds:

        return costs[n - 1]



    for i in v_nows:

        costs[i] = -INF

    que = deque(v_nows)

    while que:

        u = que.popleft()

        for v, cost in G[u]:

            if costs[v] != -INF:

                costs[v] = -INF

                que += [v]

    return costs[n - 1]





cost = bellman_ford(G, 0)

if cost == -INF:

    print((-1))

else:

    print((max(0, cost)))
from collections import deque

NegInf = -float("inf")
n, m, p = list(map(int, input().split()))
graph = [[] for _ in range(n)]
for i in range(m):
    a, b, c = list(map(int, input().split()))
    graph[a - 1].append((b - 1, c - p))


def bellman_ford(vst, graph, node_num, NegInf):
    costs = [NegInf] * node_num
    costs[0] = 0
    v_nows = set([vst])
    for _ in range(n):
        v_changeds = set()
        for v_from in v_nows:
            for v_to, cost in graph[v_from]:
                c2 = costs[v_from] + cost
                if c2 > costs[v_to]:
                    costs[v_to] = c2
                    v_changeds.add(v_to)
        v_nows = v_changeds
    if not v_changeds:
        return costs
    for i in v_nows:
        costs[i] = NegInf
    que = deque(v_nows)
    while que:
        v_from = que.popleft()
        for v_to, cost in graph[v_from]:
            if costs[v_to] != NegInf:
                costs[v_to] = NegInf
                que.append(v_to)
    return costs


costs = bellman_ford(0, graph, n, -float("inf"))
if costs[n - 1] == NegInf:
    print((-1))
else:
    print((max(0, costs[n - 1])))

from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from functools import reduce

sys.setrecursionlimit(2147483647)
INF = 10**18


def LI():
    return list(map(int, sys.stdin.buffer.readline().split()))


def I():
    return int(sys.stdin.buffer.readline())


def LS():
    return sys.stdin.buffer.readline().rstrip().decode("utf-8").split()


def S():
    return sys.stdin.buffer.readline().rstrip().decode("utf-8")


def IR(n):
    return [I() for i in range(n)]


def LIR(n):
    return [LI() for i in range(n)]


def SR(n):
    return [S() for i in range(n)]


def LSR(n):
    return [LS() for i in range(n)]


def SRL(n):
    return [list(S()) for i in range(n)]


def MSRL(n):
    return [[int(j) for j in list(S())] for i in range(n)]


mod = 1000000007
n, m, p = LI()
G = [[] for _ in range(n)]
for i in range(m):
    a, b, c = LI()
    G[a - 1] += [(b - 1, c - p)]


def bellman_ford(G, start=0):
    n = len(G)
    costs = [-INF] * n
    costs[0] = 0
    v_nows = set([start])
    for _ in range(n):
        v_changeds = set()
        for u in v_nows:
            for v, c in G[u]:
                if costs[u] + c > costs[v]:
                    costs[v] = costs[u] + c
                    v_changeds.add(v)
        v_nows = v_changeds
    if not v_changeds:
        return costs[n - 1]
    for i in v_nows:
        costs[i] = -INF
    que = deque(v_nows)
    while que:
        u = que.popleft()
        for v, cost in G[u]:
            if costs[v] != -INF:
                costs[v] = -INF
                que += [v]
    return costs[n - 1]


cost = bellman_ford(G, 0)
if cost == -INF:
    print((-1))
else:
    print((max(0, cost)))

-from collections import deque +from collections import defaultdict, deque, Counter +from heapq import heappush, heappop, heapify +import math +import bisect +import random +from itertools import permutations, accumulate, combinations, product +import sys +import string +from bisect import bisect_left, bisect_right +from math import factorial, ceil, floor +from functools import reduce -NegInf = -float("inf") -n, m, p = list(map(int, input().split())) -graph = [[] for _ in range(n)] -for i in range(m): -    a, b, c = list(map(int, input().split())) -    graph[a - 1].append((b - 1, c - p)) +sys.setrecursionlimit(2147483647) +INF = 10**18 -def bellman_ford(vst, graph, node_num, NegInf): -    costs = [NegInf] * node_num +def LI(): +    return list(map(int, sys.stdin.buffer.readline().split())) + + +def I(): +    return int(sys.stdin.buffer.readline()) + + +def LS(): +    return sys.stdin.buffer.readline().rstrip().decode("utf-8").split() + + +def S(): +    return sys.stdin.buffer.readline().rstrip().decode("utf-8") + + +def IR(n): +    return [I() for i in range(n)] + + +def LIR(n): +    return [LI() for i in range(n)] + + +def SR(n): +    return [S() for i in range(n)] + + +def LSR(n): +    return [LS() for i in range(n)] + + +def SRL(n): +    return [list(S()) for i in range(n)] + + +def MSRL(n): +    return [[int(j) for j in list(S())] for i in range(n)] + + +mod = 1000000007 +n, m, p = LI() +G = [[] for _ in range(n)] +for i in range(m): +    a, b, c = LI() +    G[a - 1] += [(b - 1, c - p)] + + +def bellman_ford(G, start=0): +    n = len(G) +    costs = [-INF] * n -    v_nows = set([vst]) +    v_nows = set([start]) -        for v_from in v_nows: -            for v_to, cost in graph[v_from]: -                c2 = costs[v_from] + cost -                if c2 > costs[v_to]: -                    costs[v_to] = c2 -                    v_changeds.add(v_to) +        for u in v_nows: +            for v, c in G[u]: +                if costs[u] + c > costs[v]: +                    costs[v] = costs[u] + c +                    v_changeds.add(v) -        return costs +        return costs[n - 1] -        costs[i] = NegInf +        costs[i] = -INF -        v_from = que.popleft() -        for v_to, cost in graph[v_from]: -            if costs[v_to] != NegInf: -                costs[v_to] = NegInf -                que.append(v_to) -    return costs +        u = que.popleft() +        for v, cost in G[u]: +            if costs[v] != -INF: +                costs[v] = -INF +                que += [v] +    return costs[n - 1] -costs = bellman_ford(0, graph, n, -float("inf")) -if costs[n - 1] == NegInf: +cost = bellman_ford(G, 0) +if cost == -INF: -    print((max(0, costs[n - 1]))) +    print((max(0, cost)))