require 'set'

N, M, P = gets.split.map(&:to_i)
edges = M.times.map do
  a, b, c = gets.split.map(&:to_i)
  [a - 1, b - 1, -(c - P)]
end
graph = Array.new(N) { [] }
edges.each do |(u, v, w)|
  graph[u].push([v, w])
end
reversed_graph = Array.new(N) { [] }
edges.each do |(u, v, w)|
  reversed_graph[v].push([u, w])
end

def reachable_vertexes(graph, s)
  visited = Set.new
  queue = [s]
  while !queue.empty?
    u = queue.shift
    visited.add(u)
    graph[u].each do |(v, _)|
      next if visited.include?(v)
      queue.push(v)
    end
  end
  visited
end

def bellman_ford(edges, s, vertex_size, inf = 1 << 60)
  d = Hash.new { inf }
  d[s] = 0
  vertex_size.times do |i|
    is_update = false
    edges.each do |(u, v, w)|
      if d[u] != inf && d[u] + w < d[v]
        d[v] = d[u] + w
        is_update = true
        return nil if i == vertex_size - 1
      end
    end
    return d if !is_update
  end
end

reachable_from_1 = reachable_vertexes(graph, 0)
reachable_to_n = reachable_vertexes(reversed_graph, N - 1)
v_set = Set.new
N.times do |v|
  v_set.add(v) if reachable_from_1.include?(v) && reachable_to_n.include?(v)
end
new_edges = edges.select do |(u, v, _)|
  v_set.include?(u) && v_set.include?(v)
end
ans = bellman_ford(new_edges, 0, v_set.size)
puts(ans == nil ? '-1' : [-(ans[N - 1]), 0].max)
