N, M, P = gets.chomp.split(" ").map(&:to_i)
E = Hash.new{|h, k| h[k] = []}
M.times{|i|
  a, b, c = gets.chomp.split(" ").map(&:to_i)
  E[a] << [b, c - P]
}

INF = 'inf'
tmp = 0
d = Array.new(N + 1, nil)
d[1] = 0
bef = [1]
(2 * N).times{|cnt|
  nxt = []
  bef.each{|from|
    E[from].each{|to, cost|
      if d[to].nil? || (d[to] < d[from] + cost) then
        d[to] = d[from] + cost
        d[to] += d[N] if to != N && cnt == N && d[N] > 0
        nxt << to
      end
    }
  }
  bef = nxt.uniq
  break if bef.empty?
  tmp = d[N] if cnt == N - 1
  (d[N] = INF; break) if cnt >= N && d[N] > tmp
}

if d[N] == INF then
  puts -1
elsif d[N] < 0 then
  puts 0
else
  puts d[N]
end
