n, m, p = gets.split.map(&:to_i)
es = m.times.map { 
  a, b, c = gets.split.map(&:to_i)
  [a-1, b-1, c-p]
}

cs = Array.new(n) { -1.0/0 }
cs[0] = 0

bf = -> do
  n.times do
    m.times do |i|
      from, to, c = es[i]
      cs[to] = cs[from] + c if cs[to] < cs[from] + c
    end
  end
end

bf.()
r = cs[n-1]
bf.()
puts(r == cs[n-1] ? [0, r].max : -1)