let [|N;M;P|] =
    stdin.ReadLine().Split()
    |> Array.map int
let edges =
    [|1..N|]
    |> Array.map (fun _ ->
        stdin.ReadLine().Split()
        |> Array.map int)
let INF = 1001001001

let edges' =
    edges
    |> Array.map (fun [|from;b;cost|] -> (from-1, b-1, P-cost))

let toMap =
    edges'
    |> Array.groupBy (fun (from,_,_) -> from)
    |> Map.ofArray
let rtoMap =
    edges'
    |> Array.groupBy (fun (_,b,_) -> b)
    |> Map.ofArray

let rec dfs1 (state:bool[]) i =
    if state.[i] then state
    else
        Array.set state i true
        if Map.containsKey i toMap then
            toMap.[i]
            |> Array.fold (fun s (_,b,_) -> dfs1 s b) state
        else state

let ok1 = dfs1 (Array.create N false) 0

let rec dfsN (state:bool[]) i =
    if state.[i] then state
    else
        Array.set state i true
        if Map.containsKey i rtoMap then
            rtoMap.[i]
            |> Array.fold (fun s (from,_,_) -> dfsN s from) state
        else state

let okN = dfsN (Array.create N false) (N-1)

let ok = Array.map2 (&&) ok1 okN

let intialState = Array.create N INF
Array.set intialState 0 0

[|0..N|]
|> Array.fold (fun (state:int[], _) i ->
    edges'
    |> Array.fold (fun (s, loop) (from,b,cost) ->
        if ok.[b] && ok.[from] && s.[b] > s.[from] + cost then
            Array.set s b (state.[from] + cost)
            if i=N then (s, true)
            else (s, loop)
        else (s, loop)) (state,false)) (intialState,false)
|> (fun (arr,loop) ->
    if loop then -1
    else max (-arr.[N-1]) 0)
|> stdout.WriteLine