using System;
using System.Collections.Generic;
using System.Linq;
using CompLib.Util;

public class Program
{
    int N, M, P;
    List<int>[] e, rev;
    Edge[] edges;
    public void Solve()
    {
        var sc = new Scanner();
        N = sc.NextInt();
        M = sc.NextInt();
        P = sc.NextInt();
        edges = new Edge[M];
        for (int i = 0; i < M; i++)
        {
            edges[i] = new Edge() { From = sc.NextInt() - 1, To = sc.NextInt() - 1, Weight = sc.NextInt() - P };
        }
        long[] ans = new long[N];
        for (int i = 0; i < N; i++)
        {
            ans[i] = long.MinValue;
        }


        e = new List<int>[N];
        rev = new List<int>[N];
        for (int i = 0; i < N; i++)
        {
            e[i] = new List<int>();
            rev[i] = new List<int>();
        }

        for (int i = 0; i < M; i++)
        {
            e[edges[i].From].Add(edges[i].To);
            rev[edges[i].To].Add(edges[i].From);
        }

        bool[] f = new bool[N];
        bool[] l = new bool[N];


        {
            f[0] = true;
            var q = new Queue<int>();
            q.Enqueue(0);
            while (q.Count > 0)
            {
                var d = q.Dequeue();
                foreach (int to in e[d])
                {
                    if (f[to]) continue;
                    f[to] = true;
                    q.Enqueue(to);
                }
            }
        }
        {
            l[N - 1] = true;
            var q = new Queue<int>();
            q.Enqueue(N - 1);
            while (q.Count > 0)
            {
                var d = q.Dequeue();
                foreach (int to in rev[d])
                {
                    if (l[to]) continue;
                    l[to] = true;
                    q.Enqueue(to);
                }
            }
        }


        ans[0] = 0;

        for (int i = 0; i < N; i++)
        {
            foreach (var e in edges)
            {
                if (ans[e.From] == long.MinValue) continue;
                ans[e.To] = Math.Max(ans[e.To], ans[e.From] + e.Weight);
            }
        }

        // Console.WriteLine(Math.Max(0, ans[N - 1]));

        for (int i = 0; i < N; i++)
        {
            // Console.WriteLine(string.Join(" ", ans));
            foreach (var e in edges)
            {
                if (ans[e.From] == long.MinValue) continue;
                if (ans[e.To] < ans[e.From] + e.Weight)
                {
                    //  Console.WriteLine($"{e.To} {e.From} {ans[e.To]}<{ans[e.From]}+{e.Weight}");
                    if (f[e.To] && l[e.To])
                    {
                        Console.WriteLine("-1");
                        return;
                    }
                    ans[e.To] = ans[e.From] + e.Weight;
                }

            }
        }

        Console.WriteLine(Math.Max(0, ans[N - 1]));
    }

    public static void Main(string[] args) => new Program().Solve();
}

struct Edge
{
    public int From, To;
    public long Weight;
}

namespace CompLib.Util
{
    using System;
    using System.Linq;

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}


Measured memory_bytes: 15424