require 'set'

class Edge
  attr_reader :from, :to, :cost

  def initialize(from, to, cost)
    @from = from
    @to = to
    @cost = cost
  end
end

INF = 10010010001

def reachable_vertexes(v, graph)
  visited = Set.new
  queue = [v]
  until queue.none?
    from = queue.shift
    visited.add(from)
    graph[from].each do |to|
      next if visited.include?(to)
      queue.push(to)
    end
  end

  visited
end


def coins_respawn(n, edges)
  graph = Array.new(n) { [] }
  r_graph = Array.new(n) { [] }
  edges.each do |e|
    graph[e.from] << e.to
    r_graph[e.to] << e.from
  end

  vertexes = reachable_vertexes(0, graph) & reachable_vertexes(n - 1, r_graph)
  edges.select! { |e| vertexes.include?(e.from) && vertexes.include?(e.to) }

  d = Array.new(n, INF)
  d[0] = 0

  (n + 1).times do |i|
    updated = false
    edges.each do |e|
      if d[e.from] != INF && d[e.to] > d[e.from] + e.cost
        d[e.to] = d[e.from] + e.cost
        updated = true

        if i == n
          puts -1
          exit
        end
      end
    end
    break unless updated
  end

  [d[n - 1] * -1, 0].max
end

n, m, p = gets.split.map(&:to_i)
edges = []
m.times do
  param = gets.split.map(&:to_i)
  edges << Edge.new(param[0] - 1, param[1] - 1, (param[2] - p) * -1)
end
 
puts coins_respawn(n, edges)