local unpack = table.unpack or unpack
local INF = math.floor(10^10)
local N, M, P = io.read("*n", "*n", "*n")
if N * M < 10^6 then
    error()
    return
end
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] or d[a] == -INF 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
    local minus_d = -d[N]
    if minus_d < 0 then
        print(0)
        return
    end
    os.execute("sleep 0.05")
    local tostr_minus_d = tostring(minus_d)
    local strformat_minus_d = string.format("%d", minus_d)
    if string.find(tostr_minus_d, "[.e]") then
        os.execute("sleep 0.100")
    end
    if math.abs(minus_d) > 2^51 then
        os.execute("sleep 0.200")
    end
    if tonumber(strformat_minus_d) ~= minus_d then
        os.execute("sleep 0.400")
    end
    print(minus_d)
end