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]
}

INT = -2
INF = -1
tmp = INT
d = Array.new(N + 1, INT)
d[1] = 0
(2 * N).times{|cnt|
  upd = false
  E.each{|from, v|
    v.each{|to, cost|
      if d[from] != INT && d[to] < d[from] + cost then
        d[to] = d[from] + cost
        d[to] = d[N] if to != N && cnt == N
        upd = true
      end
    }
  }
  break if not upd
  tmp = d[N] if cnt == N - 1
  (d[N] = INF; break) if cnt >= N && d[N] > tmp
}

puts d[N] == INT ? 0 : d[N]
