def Bellman_Ford(s, g, inf=1 << 60):

    # https://tjkendev.github.io/procon-library/python/graph/bellman-ford.html

    N = len(g)

    dist = [inf] * N

    dist[s] = 0

    for _ in range(N):

        not_updated = True

        for v in range(N):

            for u, c in g[v]:

                if (dist[v] == inf) or (dist[v] + c >= dist[u]): continue

                dist[u] = dist[v] + c

                not_updated = False



        if not_updated:

            return max(0, -dist[N - 1])



    # 負閉路が存在する

    for _ in range(N):

        not_updated = True

        for v in range(N):

            for u, c in g[v]:

                if (dist[v] == inf) or (dist[v] + c >= dist[u]): continue

                dist[u] = -inf

                not_updated = False

        if not_updated: break



    if dist[N - 1] == -inf:

        return -1

    else:

        return max(0, -dist[N - 1])





def main():

    import sys

    input = sys.stdin.readline



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



    g = tuple(set() for _ in range(N))

    for _ in range(M):

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

        a -= 1

        b -= 1

        g[a].add((b, -(c - P)))  # to,coin(負辺)



    ret = Bellman_Ford(0, g)

    print(ret)





if __name__ == '__main__':

    main()

def main():

    from collections import deque

    import sys

    input = sys.stdin.readline



    inf = 1 << 60



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



    to = tuple(set() for _ in range(N))

    ot = tuple(set() for _ in range(N))

    for _ in range(M):

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

        a -= 1

        b -= 1

        to[a].add((b, -(c - P)))  # to,coin(負辺)

        ot[b].add((a, -(c - P)))  # to,coin(負辺)



    def reach(s, g, result):

        dq = deque()

        dq.append(s)

        while dq:

            v = dq.popleft()

            for u, _ in g[v]:

                if result[u]: continue

                result[u] = 1

                dq.append(u)



    reachable_from_N = [0] * N

    reachable_from_N[N - 1] = 1

    reach(N - 1, ot, reachable_from_N)



    reachable_from_1 = [0] * N

    reachable_from_1[0] = 1

    reach(0, to, reachable_from_1)



    unreachable = tuple(1 ^ (rn & r1) for rn, r1 in zip(reachable_from_N, reachable_from_1))



    def bellman_ford(dist):

        for _ in range(N):

            not_updated = True

            for v in range(N):

                for u, c in to[v]:

                    if unreachable[u]: continue

                    if (dist[v] == inf) or (dist[v] + c >= dist[u]): continue

                    dist[u] = dist[v] + c

                    not_updated = False

            if not_updated: return False



        for v in range(N):  # 負閉路検知

            for u, c in to[v]:

                if unreachable[u]: continue

                if (dist[v] == inf) or (dist[v] + c >= dist[u]): continue

                return True

        return False



    dist = [inf] * N

    dist[0] = 0

    cond = bellman_ford(dist=dist)



    if cond:

        print((-1))

    else:

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





if __name__ == '__main__':

    main()

def Bellman_Ford(s, g, inf=1 << 60):
    # https://tjkendev.github.io/procon-library/python/graph/bellman-ford.html
    N = len(g)
    dist = [inf] * N
    dist[s] = 0
    for _ in range(N):
        not_updated = True
        for v in range(N):
            for u, c in g[v]:
                if (dist[v] == inf) or (dist[v] + c >= dist[u]):
                    continue
                dist[u] = dist[v] + c
                not_updated = False
        if not_updated:
            return max(0, -dist[N - 1])
    # 負閉路が存在する
    for _ in range(N):
        not_updated = True
        for v in range(N):
            for u, c in g[v]:
                if (dist[v] == inf) or (dist[v] + c >= dist[u]):
                    continue
                dist[u] = -inf
                not_updated = False
        if not_updated:
            break
    if dist[N - 1] == -inf:
        return -1
    else:
        return max(0, -dist[N - 1])


def main():
    import sys

    input = sys.stdin.readline
    N, M, P = list(map(int, input().split()))
    g = tuple(set() for _ in range(N))
    for _ in range(M):
        a, b, c = list(map(int, input().split()))
        a -= 1
        b -= 1
        g[a].add((b, -(c - P)))  # to,coin(負辺)
    ret = Bellman_Ford(0, g)
    print(ret)


if __name__ == "__main__":
    main()

def main():
    from collections import deque
    import sys

    input = sys.stdin.readline
    inf = 1 << 60
    N, M, P = list(map(int, input().split()))
    to = tuple(set() for _ in range(N))
    ot = tuple(set() for _ in range(N))
    for _ in range(M):
        a, b, c = list(map(int, input().split()))
        a -= 1
        b -= 1
        to[a].add((b, -(c - P)))  # to,coin(負辺)
        ot[b].add((a, -(c - P)))  # to,coin(負辺)

    def reach(s, g, result):
        dq = deque()
        dq.append(s)
        while dq:
            v = dq.popleft()
            for u, _ in g[v]:
                if result[u]:
                    continue
                result[u] = 1
                dq.append(u)

    reachable_from_N = [0] * N
    reachable_from_N[N - 1] = 1
    reach(N - 1, ot, reachable_from_N)
    reachable_from_1 = [0] * N
    reachable_from_1[0] = 1
    reach(0, to, reachable_from_1)
    unreachable = tuple(
        1 ^ (rn & r1) for rn, r1 in zip(reachable_from_N, reachable_from_1)
    )

    def bellman_ford(dist):
        for _ in range(N):
            not_updated = True
            for v in range(N):
                for u, c in to[v]:
                    if unreachable[u]:
                        continue
                    if (dist[v] == inf) or (dist[v] + c >= dist[u]):
                        continue
                    dist[u] = dist[v] + c
                    not_updated = False
            if not_updated:
                return False
        for v in range(N):  # 負閉路検知
            for u, c in to[v]:
                if unreachable[u]:
                    continue
                if (dist[v] == inf) or (dist[v] + c >= dist[u]):
                    continue
                return True
        return False

    dist = [inf] * N
    dist[0] = 0
    cond = bellman_ford(dist=dist)
    if cond:
        print((-1))
    else:
        print((max(0, -dist[N - 1])))


if __name__ == "__main__":
    main()

-def Bellman_Ford(s, g, inf=1 << 60): -    # https://tjkendev.github.io/procon-library/python/graph/bellman-ford.html -    N = len(g) -    dist = [inf] * N -    dist[s] = 0 -    for _ in range(N): -        not_updated = True -        for v in range(N): -            for u, c in g[v]: -                if (dist[v] == inf) or (dist[v] + c >= dist[u]): -                    continue -                dist[u] = dist[v] + c -                not_updated = False -        if not_updated: -            return max(0, -dist[N - 1]) -    # 負閉路が存在する -    for _ in range(N): -        not_updated = True -        for v in range(N): -            for u, c in g[v]: -                if (dist[v] == inf) or (dist[v] + c >= dist[u]): -                    continue -                dist[u] = -inf -                not_updated = False -        if not_updated: -            break -    if dist[N - 1] == -inf: -        return -1 -    else: -        return max(0, -dist[N - 1]) - - +    from collections import deque +    inf = 1 << 60 -    g = tuple(set() for _ in range(N)) +    to = tuple(set() for _ in range(N)) +    ot = tuple(set() for _ in range(N)) -        g[a].add((b, -(c - P)))  # to,coin(負辺) -    ret = Bellman_Ford(0, g) -    print(ret) +        to[a].add((b, -(c - P)))  # to,coin(負辺) +        ot[b].add((a, -(c - P)))  # to,coin(負辺) + +    def reach(s, g, result): +        dq = deque() +        dq.append(s) +        while dq: +            v = dq.popleft() +            for u, _ in g[v]: +                if result[u]: +                    continue +                result[u] = 1 +                dq.append(u) + +    reachable_from_N = [0] * N +    reachable_from_N[N - 1] = 1 +    reach(N - 1, ot, reachable_from_N) +    reachable_from_1 = [0] * N +    reachable_from_1[0] = 1 +    reach(0, to, reachable_from_1) +    unreachable = tuple( +        1 ^ (rn & r1) for rn, r1 in zip(reachable_from_N, reachable_from_1) +    ) + +    def bellman_ford(dist): +        for _ in range(N): +            not_updated = True +            for v in range(N): +                for u, c in to[v]: +                    if unreachable[u]: +                        continue +                    if (dist[v] == inf) or (dist[v] + c >= dist[u]): +                        continue +                    dist[u] = dist[v] + c +                    not_updated = False +            if not_updated: +                return False +        for v in range(N):  # 負閉路検知 +            for u, c in to[v]: +                if unreachable[u]: +                    continue +                if (dist[v] == inf) or (dist[v] + c >= dist[u]): +                    continue +                return True +        return False + +    dist = [inf] * N +    dist[0] = 0 +    cond = bellman_ford(dist=dist) +    if cond: +        print((-1)) +    else: +        print((max(0, -dist[N - 1])))