(N, M, P), *ABCs = readlines.map{|l| l.split.map(&:to_i)}
INF = 1E10.to_i

g, to, from = [], Array.new(N + 1){[]}, Array.new(N + 1){[]}
ABCs.each do |a, b, c|
  g << [a, b, P - c]
  from[a] << b
  to[b] << a
end
f = ->(a, x){
  r = Array.new(N + 1, false); r[x] = true
  h = ->(y){a[y].reject{|z| r[z]}.each{|t| r[t] = true; h[t]}}
  h[x]; r
}
c = f[from, 1].zip(f[to, N]).map{|a, b| a && b}
g.select!{|a, b, _| c[a] && c[b]}
d = Array.new(N + 1, INF); d[1] = 0
c.count(true).times do
  f = false
  g.each do |a, b, e|
    if d[a] != INF && d[b] > (t = d[a] + e)
      d[b] = t
      f = true
    end
  end
  (puts [-d[N], 0].max; exit) unless f
end
puts -1