#!/usr/bin/env python3

from collections import defaultdict,deque

from heapq import heappush, heappop

from bisect import bisect_left, bisect_right

import sys, random, itertools, math

sys.setrecursionlimit(10**5)

input = sys.stdin.readline

sqrt = math.sqrt

def LI(): return list(map(int, input().split()))

def LF(): return list(map(float, input().split()))

def LI_(): return list([int(x)-1 for x in input().split()])

def II(): return int(eval(input()))

def IF(): return float(eval(input()))

def LS(): return list(map(list, input().split()))

def S(): return list(input().rstrip())

def IR(n): return [II() for _ in range(n)]

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

def FR(n): return [IF() for _ in range(n)]

def LFR(n): return [LI() for _ in range(n)]

def LIR_(n): return [LI_() for _ in range(n)]

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

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

mod = 1000000007

inf = float('INF')



#A

def A():

    a, b = LI()

    print((max(a + b, a - b, a * b)))

    return



#B

def B():

    k, x = LI()

    ans = []

    for i in range(x - k + 1, x + k):

        ans.append(i)

    print((*ans))

    return



#C

def C():

    n = II()

    d = defaultdict(int)

    for _ in range(n):

        s = S()

        s.sort()

        d[tuple(s)] += 1

    ans = 0

    for i in list(d.values()):

        ans += i * (i - 1) // 2

    print(ans)

    return



# D

# 解説AC

# 後方から見ていくのはわかったけど。。。

# i日前に選べるバイトの中から一番報酬が大きいを選んでいく

def D():

    n, m = LI()

    q = []

    d = defaultdict(list)

    ans = 0

    for _ in range(n):

        a, b = LI()

        d[a].append(b)

    for i in range(m):

        for di in d[i+1]:

            heappush(q, -di)

        if q:

            ans -= heappop(q)

    print(ans)

    return



#E

def E():

    n,m,p = LI()

    dag = [-inf] * n

    edg = LIR_(m)

    dag[0] = 0

    for i in range(n):

        for a, b, c in edg:

            c += 1

            c -= p

            if dag[a] + c > dag[b]:

                dag[b] = dag[a] + c

    ans = dag[n - 1]

    for i in range(n):

        for a, b, c in edg:

            c += 1

            c -= p

            if dag[a] + c > dag[b]:

                dag[b] = inf

    if ans != dag[n - 1]:

        print((-1))

    else:

        print((max(ans, 0)))



    return



#F

def F():

    return



#Solve

if __name__ == '__main__':

    E()

#!/usr/bin/env python3

from collections import defaultdict,deque

from heapq import heappush, heappop

from bisect import bisect_left, bisect_right

import sys, itertools, math

sys.setrecursionlimit(10**5)

input = sys.stdin.readline

sqrt = math.sqrt

def LI(): return list(map(int, input().split()))

def LF(): return list(map(float, input().split()))

def LI_(): return list([int(x)-1 for x in input().split()])

def II(): return int(eval(input()))

def IF(): return float(eval(input()))

def S(): return input().rstrip()

def LS(): return S().split()

def IR(n):

    res = [None] * n

    for i in range(n):

        res[i] = II()

    return res

def LIR(n):

    res = [None] * n

    for i in range(n):

        res[i] = LI()

    return res

def FR(n):

    res = [None] * n

    for i in range(n):

        res[i] = IF()

    return res

def LIR(n):

    res = [None] * n

    for i in range(n):

        res[i] = IF()

    return res

def LIR_(n):

    res = [None] * n

    for i in range(n):

        res[i] = LI_()

    return res

def SR(n):

    res = [None] * n

    for i in range(n):

        res[i] = S()

    return res

def LSR(n):

    res = [None] * n

    for i in range(n):

        res[i] = LS()

    return res

mod = 1000000007

inf = float('INF')



#solve

def solve():

    n, m, p = LI()

    edg = [[] for i in range(n)]

    for _ in range(m):

        a, b, c = LI_()

        c += 1

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

    dp = [-inf] * n

    dp[0] = 0

    for j in range(n):

        for i in range(n):

            score = dp[i]

            for e, s in edg[i]:

                if dp[e] < score + s - p:

                    dp[e] = score + s - p

    ans = dp[:]

    for j in range(n):

        for i in range(n):

            score = dp[i]

            for e, s in edg[i]:

                if dp[e] < score + s - p:

                    dp[e] = inf

    if ans[-1] != dp[-1]:

        print((-1))

    else:

        print((abs(max(ans[-1],0))))

    return





#main

if __name__ == '__main__':

    solve()

#!/usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math

sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt


def LI():
    return list(map(int, input().split()))


def LF():
    return list(map(float, input().split()))


def LI_():
    return list([int(x) - 1 for x in input().split()])


def II():
    return int(eval(input()))


def IF():
    return float(eval(input()))


def LS():
    return list(map(list, input().split()))


def S():
    return list(input().rstrip())


def IR(n):
    return [II() for _ in range(n)]


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


def FR(n):
    return [IF() for _ in range(n)]


def LFR(n):
    return [LI() for _ in range(n)]


def LIR_(n):
    return [LI_() for _ in range(n)]


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


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


mod = 1000000007
inf = float("INF")
# A
def A():
    a, b = LI()
    print((max(a + b, a - b, a * b)))
    return


# B
def B():
    k, x = LI()
    ans = []
    for i in range(x - k + 1, x + k):
        ans.append(i)
    print((*ans))
    return


# C
def C():
    n = II()
    d = defaultdict(int)
    for _ in range(n):
        s = S()
        s.sort()
        d[tuple(s)] += 1
    ans = 0
    for i in list(d.values()):
        ans += i * (i - 1) // 2
    print(ans)
    return


# D
# 解説AC
# 後方から見ていくのはわかったけど。。。
# i日前に選べるバイトの中から一番報酬が大きいを選んでいく
def D():
    n, m = LI()
    q = []
    d = defaultdict(list)
    ans = 0
    for _ in range(n):
        a, b = LI()
        d[a].append(b)
    for i in range(m):
        for di in d[i + 1]:
            heappush(q, -di)
        if q:
            ans -= heappop(q)
    print(ans)
    return


# E
def E():
    n, m, p = LI()
    dag = [-inf] * n
    edg = LIR_(m)
    dag[0] = 0
    for i in range(n):
        for a, b, c in edg:
            c += 1
            c -= p
            if dag[a] + c > dag[b]:
                dag[b] = dag[a] + c
    ans = dag[n - 1]
    for i in range(n):
        for a, b, c in edg:
            c += 1
            c -= p
            if dag[a] + c > dag[b]:
                dag[b] = inf
    if ans != dag[n - 1]:
        print((-1))
    else:
        print((max(ans, 0)))
    return


# F
def F():
    return


# Solve
if __name__ == "__main__":
    E()

#!/usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, itertools, math

sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt


def LI():
    return list(map(int, input().split()))


def LF():
    return list(map(float, input().split()))


def LI_():
    return list([int(x) - 1 for x in input().split()])


def II():
    return int(eval(input()))


def IF():
    return float(eval(input()))


def S():
    return input().rstrip()


def LS():
    return S().split()


def IR(n):
    res = [None] * n
    for i in range(n):
        res[i] = II()
    return res


def LIR(n):
    res = [None] * n
    for i in range(n):
        res[i] = LI()
    return res


def FR(n):
    res = [None] * n
    for i in range(n):
        res[i] = IF()
    return res


def LIR(n):
    res = [None] * n
    for i in range(n):
        res[i] = IF()
    return res


def LIR_(n):
    res = [None] * n
    for i in range(n):
        res[i] = LI_()
    return res


def SR(n):
    res = [None] * n
    for i in range(n):
        res[i] = S()
    return res


def LSR(n):
    res = [None] * n
    for i in range(n):
        res[i] = LS()
    return res


mod = 1000000007
inf = float("INF")
# solve
def solve():
    n, m, p = LI()
    edg = [[] for i in range(n)]
    for _ in range(m):
        a, b, c = LI_()
        c += 1
        edg[a].append((b, c))
    dp = [-inf] * n
    dp[0] = 0
    for j in range(n):
        for i in range(n):
            score = dp[i]
            for e, s in edg[i]:
                if dp[e] < score + s - p:
                    dp[e] = score + s - p
    ans = dp[:]
    for j in range(n):
        for i in range(n):
            score = dp[i]
            for e, s in edg[i]:
                if dp[e] < score + s - p:
                    dp[e] = inf
    if ans[-1] != dp[-1]:
        print((-1))
    else:
        print((abs(max(ans[-1], 0))))
    return


# main
if __name__ == "__main__":
    solve()

-import sys, random, itertools, math +import sys, itertools, math -def LS(): -    return list(map(list, input().split())) +def S(): +    return input().rstrip() -def S(): -    return list(input().rstrip()) +def LS(): +    return S().split() -    return [II() for _ in range(n)] +    res = [None] * n +    for i in range(n): +        res[i] = II() +    return res -    return [LI() for _ in range(n)] +    res = [None] * n +    for i in range(n): +        res[i] = LI() +    return res -    return [IF() for _ in range(n)] +    res = [None] * n +    for i in range(n): +        res[i] = IF() +    return res -def LFR(n): -    return [LI() for _ in range(n)] +def LIR(n): +    res = [None] * n +    for i in range(n): +        res[i] = IF() +    return res -    return [LI_() for _ in range(n)] +    res = [None] * n +    for i in range(n): +        res[i] = LI_() +    return res -    return [S() for _ in range(n)] +    res = [None] * n +    for i in range(n): +        res[i] = S() +    return res -    return [LS() for _ in range(n)] +    res = [None] * n +    for i in range(n): +        res[i] = LS() +    return res -# A -def A(): -    a, b = LI() -    print((max(a + b, a - b, a * b))) +# solve +def solve(): +    n, m, p = LI() +    edg = [[] for i in range(n)] +    for _ in range(m): +        a, b, c = LI_() +        c += 1 +        edg[a].append((b, c)) +    dp = [-inf] * n +    dp[0] = 0 +    for j in range(n): +        for i in range(n): +            score = dp[i] +            for e, s in edg[i]: +                if dp[e] < score + s - p: +                    dp[e] = score + s - p +    ans = dp[:] +    for j in range(n): +        for i in range(n): +            score = dp[i] +            for e, s in edg[i]: +                if dp[e] < score + s - p: +                    dp[e] = inf +    if ans[-1] != dp[-1]: +        print((-1)) +    else: +        print((abs(max(ans[-1], 0)))) -# B -def B(): -    k, x = LI() -    ans = [] -    for i in range(x - k + 1, x + k): -        ans.append(i) -    print((*ans)) -    return - - -# C -def C(): -    n = II() -    d = defaultdict(int) -    for _ in range(n): -        s = S() -        s.sort() -        d[tuple(s)] += 1 -    ans = 0 -    for i in list(d.values()): -        ans += i * (i - 1) // 2 -    print(ans) -    return - - -# D -# 解説AC -# 後方から見ていくのはわかったけど。。。 -# i日前に選べるバイトの中から一番報酬が大きいを選んでいく -def D(): -    n, m = LI() -    q = [] -    d = defaultdict(list) -    ans = 0 -    for _ in range(n): -        a, b = LI() -        d[a].append(b) -    for i in range(m): -        for di in d[i + 1]: -            heappush(q, -di) -        if q: -            ans -= heappop(q) -    print(ans) -    return - - -# E -def E(): -    n, m, p = LI() -    dag = [-inf] * n -    edg = LIR_(m) -    dag[0] = 0 -    for i in range(n): -        for a, b, c in edg: -            c += 1 -            c -= p -            if dag[a] + c > dag[b]: -                dag[b] = dag[a] + c -    ans = dag[n - 1] -    for i in range(n): -        for a, b, c in edg: -            c += 1 -            c -= p -            if dag[a] + c > dag[b]: -                dag[b] = inf -    if ans != dag[n - 1]: -        print((-1)) -    else: -        print((max(ans, 0))) -    return - - -# F -def F(): -    return - - -# Solve +# main -    E() +    solve()