INF = 10**18

n, m, p = [int(item) for item in input().split()]

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

for i in range(m):

    a, b, c = [int(item) for item in input().split()]

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

    c *= -1

    edge[a].append((b, c))

 

dist = [INF] * n

dist[0] = 0

update = 1

terminal_update = 0

for _ in range(n * 2):

    update = 0

    for v, e in enumerate(edge):

        for t, cost in e:

            if dist[v] != INF and dist[v] + cost < dist[t]:

                dist[t] = dist[v] + cost

                update = 1

                if t == n-1:

                    terminal_update += 1

    if not update:

        print((max(0, -dist[n-1])))

        exit()

else:

    if terminal_update > 1:

        print((-1))

    else:

        print((max(0, -dist[n-1])))
import sys

sys.setrecursionlimit(10**6)

INF = 10**10

 

def dfs(edge, visited, n):

    if visited[n]:

        return

    visited[n] = True

    for to, _ in edge[n]:

        dfs(edge, visited, to)



def bellman_ford(edge, mask):

    dist = [INF] * n

    dist[0] = 0



    for _ in range(n):

        update = False

        for i, es in enumerate(edge):

            if not mask[i]:

                continue

            for to, cost in es:

                if not mask[to]:

                    continue

                if dist[i] != INF and dist[i] + cost < dist[to]:

                    dist[to] = dist[i] + cost

                    update = True

        if not update:

            return dist

    else:

        # Found minus loops

        return -INF



if __name__ == "__main__":

    n, m, p = [int(item) for item in input().split()]

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

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

    for i in range(m):

        a, b, c = [int(item) for item in input().split()]

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

        c *= -1

        edge[a].append((b, c))

        redge[b].append((a, c)) 

    

    visited = [False] * n

    dfs(edge, visited, 0)

    rvisited = [False] * n

    dfs(redge, rvisited, n-1)

    mask = [forward and backward for forward, backward in zip(visited, rvisited)]

    dist = bellman_ford(edge, mask)

    if dist == -INF:

        print((-1))

    else:

        print((max(0, -dist[n-1])))
INF = 10**18
n, m, p = [int(item) for item in input().split()]
edge = [[] for _ in range(n)]
for i in range(m):
    a, b, c = [int(item) for item in input().split()]
    a -= 1
    b -= 1
    c -= p
    c *= -1
    edge[a].append((b, c))
dist = [INF] * n
dist[0] = 0
update = 1
terminal_update = 0
for _ in range(n * 2):
    update = 0
    for v, e in enumerate(edge):
        for t, cost in e:
            if dist[v] != INF and dist[v] + cost < dist[t]:
                dist[t] = dist[v] + cost
                update = 1
                if t == n - 1:
                    terminal_update += 1
    if not update:
        print((max(0, -dist[n - 1])))
        exit()
else:
    if terminal_update > 1:
        print((-1))
    else:
        print((max(0, -dist[n - 1])))

import sys

sys.setrecursionlimit(10**6)
INF = 10**10


def dfs(edge, visited, n):
    if visited[n]:
        return
    visited[n] = True
    for to, _ in edge[n]:
        dfs(edge, visited, to)


def bellman_ford(edge, mask):
    dist = [INF] * n
    dist[0] = 0
    for _ in range(n):
        update = False
        for i, es in enumerate(edge):
            if not mask[i]:
                continue
            for to, cost in es:
                if not mask[to]:
                    continue
                if dist[i] != INF and dist[i] + cost < dist[to]:
                    dist[to] = dist[i] + cost
                    update = True
        if not update:
            return dist
    else:
        # Found minus loops
        return -INF


if __name__ == "__main__":
    n, m, p = [int(item) for item in input().split()]
    edge = [[] for _ in range(n)]
    redge = [[] for _ in range(n)]
    for i in range(m):
        a, b, c = [int(item) for item in input().split()]
        a -= 1
        b -= 1
        c -= p
        c *= -1
        edge[a].append((b, c))
        redge[b].append((a, c))
    visited = [False] * n
    dfs(edge, visited, 0)
    rvisited = [False] * n
    dfs(redge, rvisited, n - 1)
    mask = [forward and backward for forward, backward in zip(visited, rvisited)]
    dist = bellman_ford(edge, mask)
    if dist == -INF:
        print((-1))
    else:
        print((max(0, -dist[n - 1])))

-INF = 10**18 -n, m, p = [int(item) for item in input().split()] -edge = [[] for _ in range(n)] -for i in range(m): -    a, b, c = [int(item) for item in input().split()] -    a -= 1 -    b -= 1 -    c -= p -    c *= -1 -    edge[a].append((b, c)) -dist = [INF] * n -dist[0] = 0 -update = 1 -terminal_update = 0 -for _ in range(n * 2): -    update = 0 -    for v, e in enumerate(edge): -        for t, cost in e: -            if dist[v] != INF and dist[v] + cost < dist[t]: -                dist[t] = dist[v] + cost -                update = 1 -                if t == n - 1: -                    terminal_update += 1 -    if not update: -        print((max(0, -dist[n - 1]))) -        exit() -else: -    if terminal_update > 1: +import sys + +sys.setrecursionlimit(10**6) +INF = 10**10 + + +def dfs(edge, visited, n): +    if visited[n]: +        return +    visited[n] = True +    for to, _ in edge[n]: +        dfs(edge, visited, to) + + +def bellman_ford(edge, mask): +    dist = [INF] * n +    dist[0] = 0 +    for _ in range(n): +        update = False +        for i, es in enumerate(edge): +            if not mask[i]: +                continue +            for to, cost in es: +                if not mask[to]: +                    continue +                if dist[i] != INF and dist[i] + cost < dist[to]: +                    dist[to] = dist[i] + cost +                    update = True +        if not update: +            return dist +    else: +        # Found minus loops +        return -INF + + +if __name__ == "__main__": +    n, m, p = [int(item) for item in input().split()] +    edge = [[] for _ in range(n)] +    redge = [[] for _ in range(n)] +    for i in range(m): +        a, b, c = [int(item) for item in input().split()] +        a -= 1 +        b -= 1 +        c -= p +        c *= -1 +        edge[a].append((b, c)) +        redge[b].append((a, c)) +    visited = [False] * n +    dfs(edge, visited, 0) +    rvisited = [False] * n +    dfs(redge, rvisited, n - 1) +    mask = [forward and backward for forward, backward in zip(visited, rvisited)] +    dist = bellman_ford(edge, mask) +    if dist == -INF: