local mma = math.max
local n, m, p = io.read("*n", "*n", "*n")
local edge = {}
for i = 1, n do edge[i] = {} end
for i = 1, m do
  local a, b, c = io.read("*n", "*n", "*n")
  c = c - p
  edge[a][b] = c
end

local taskstate = {}
for i = 1, n do taskstate[i] = false end
local tasks = {}
local tasknum = 0
local done = 0
local tasklim = n + 1
local updatecount = 0
local len = {}
for i = 1, n do len[i] = -1000000000000 end
len[1] = 0
local updatecount = {}
for i = 1, n do
  updatecount[i] = 0
end
local inf = 10000000000
local function addtask(idx, flg)
  if(not taskstate[idx]) then
    taskstate[idx] = true
    tasknum = tasknum + 1
    local taskidx = tasknum % tasklim
    if taskidx == 0 then taskidx = tasklim end
    tasks[taskidx] = idx
    if not flg then
      updatecount[idx] = updatecount[idx] + 1
    end
  end
end
addtask(1)

while(done < tasknum) do
  done = done + 1
  local taskidx = done % tasklim
  if(taskidx == 0) then taskidx = tasklim end
  local src = tasks[taskidx]
  taskstate[src] = false

  for dst, cost in pairs(edge[src]) do
    if len[dst] < inf then
      if inf <= len[src] or len[dst] <= len[src] + cost then
        if n + 3 < updatecount[dst] then
          len[dst] = inf
        else
          if inf <= len[src] then
            len[dst] = inf
          elseif len[dst] < len[src] + cost then
            len[dst] = len[src] + cost
          else
            addtask(dst, true)
          end
        end
        addtask(dst)
      end
    end
  end
  if n + 3 < updatecount[n] then len[n] = inf break end
end
if inf <= len[n] then
  print("-1")
else
  print(mma(0, len[n]))
end
