n, m, p = gets.split.map(&:to_i)
@t = Array.new(n) { [] }
m.times do
  a, b, c = gets.split.map(&:to_i)
  @t[a-1] << [b-1, c - p]
end

@inf = 1.0/0
@memo = Array.new(n) { -@inf }
@memo[0] = 0

def walk i, fs
  @t[i].each do |to, c|
    if fs[to]
      if @memo[to] < @memo[i] + c
        @memo[to] = @inf
        walk to, fs
      end
    else
      if @memo[to] < @memo[i] + c
        @memo[to] = @memo[i] + c
        fs[i] = true
        walk to, fs
        fs[i] = false
      end
    end
  end
end

fs = Array.new(n) { false }
fs[0] = true
walk 0, fs
puts(@memo.last.abs == @inf ? -1 : [0, @memo.last].max)