local unpack = table.unpack or unpack
local INF = math.floor(10^10)
local N, M, P = io.read("*n", "*n", "*n")
local edges = {}
for i=1,M do
    local a, b, c = io.read("*n", "*n", "*n")
    edges[i] = {a, b, -1 * (c - P)}
end


-- Bellman-Ford
local function bf()
    -- distance from 1
    local d = {}
    for i=1,N do
        d[i] = INF
    end
    d[1] = 0
    for i=1,N-1 do
        for j=1,M do
            local a, b, w = unpack(edges[j])
            if d[a] ~= INF then
                local new_d = d[a] + w
                if new_d < d[b] then
                    d[b] = new_d
                end
            end
        end
    end
    for i=1,N do
        for j=1,M do
            local a, b, w = unpack(edges[j])
            if d[a] ~= INF then
                if d[a] + w < d[b] then
                    d[b] = -INF
                end
            end
        end
    end
    return d
end

local d = bf()
local negloop = d[N] == -INF
if negloop then
    print(-1)
else
    print(math.max(0,-d[N]))
end