n, m, tax = gets.strip.split.map(&:to_i)
abc = readlines.map {|line| 
  tmp = line.strip.split.map(&:to_i)
  [tmp[0], tmp[1], -1*(tmp.last-tax)]
}
N=n

graph=Array.new(n+1) {[]}
reverse_graph=Array.new(n+1) {[]}
abc.each do |a, b, tax|
  graph[a] << [b, tax]
  reverse_graph[b] << [a, tax]
end

# sから到達可能、gに到達可能の点を洗い出す
# 洗い出した点のみを使うように再構成
# ベルマンフォード法で最短距離をゲット、
# 合計値をゲットして完了

def reachable(graph, s)
  visited = [s]
  queue = [s]
  until queue.empty?
    current = queue.shift
    graph[current].each do |to, _|
      next if visited.include?(to)
      visited.push(to)
      queue.push(to)
    end
  end

  visited
end

INF = 10**13
@dist = Array.new(n+1, INF)

def berman_ford(edges, s, g)
  @dist[s]=0
  N.times do |i|
    updated = false
    edges.each do |from, to, cost|
      if @dist[from] != INF && @dist[to] > @dist[from] + cost
        @dist[to] = @dist[from]+cost
        updated = true
      end
    end
    return true unless updated
  end

  return false
end

reachable_from_s = reachable(graph, 1)
reachable_to_g = reachable(reverse_graph, n)
retrenched_nodes = reachable_from_s & reachable_to_g

retrenched_edges = abc.select{|from, to, _|
  retrenched_nodes.include?(from) && retrenched_nodes.include?(to)
}

result = -1

if berman_ford(retrenched_edges, 1, n)
  result = [-1*@dist[n], 0].max
end

#p reachable_from_s
#p reachable_to_g
#p retrenched_nodes
#p retrenched_edges
#p @dist
p result

