local n, m, p = io.read("*n", "*n", "*n")
local edge = {}
local srcs, dsts, cs = {}, {}, {}
for i = 1, m do
  local a, b, c = io.read("*n", "*n", "*n")
  srcs[i] = a
  dsts[i] = b
  cs[i] = c - p
end
local len = {}
local inf = 10000000000
for i = 1, n do len[i] = -inf end
len[1] = 0
local lim = n + 4
for i = 1, lim do
  for j = 1, m do
    local src, dst, c = srcs[j], dsts[j], cs[j]
    if len[src] ~= -inf and len[dst] < len[src] + c then
      len[dst] = len[src] + c
      if i == lim then
        len[dst] = inf
      end
    end
  end
end
for i = 1, lim do
  for j = 1, m do
    local src, dst, c = srcs[j], dsts[j], cs[j]
    if len[src] == inf then
      len[dst] = inf
    end
  end
end
print(inf <= len[n] and -1 or math.max(0, len[n]))
