using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCorder
{
	public class Program
	{
		static void Main(string[] args)
		{
			Scanner cin = new Scanner();
			int n = cin.Int();
			int m = cin.Int();
			int p = cin.Int();

			var bf = new BellmanFord(n);
			for (int i = 0; i < m; i++) {
				int a = cin.Int();
				int b = cin.Int();
				int c = cin.Int();
				bf.AddEdge(a - 1, b - 1, -1 * (c - p));
			}

			bool existsNegativeCycle;
			long ans = bf.CalculateDistance(0, n - 1, out existsNegativeCycle);
			if (existsNegativeCycle) {
				Console.WriteLine(-1);
				return;
			}

			ans *= - 1;
			ans = Math.Max(0, ans);

			Console.WriteLine(ans);
		}
	}

	public class BellmanFord
	{
		private const long INFINITY = long.MaxValue;

		private readonly int count_;
		private readonly List<Edge> edges_;
		private readonly List<int>[] to_;
		private readonly List<int>[] from_;

		public BellmanFord(int count)
		{
			count_ = count;
			edges_ = new List<Edge>(count);
			to_ = Enumerable.Range(0, count).Select(x => new List<int>()).ToArray();
			from_ = Enumerable.Range(0, count).Select(x => new List<int>()).ToArray();
		}

		public void AddEdge(int from, int to, int cost)
		{
			edges_.Add(new Edge { From = from, To = to, Cost = cost });
			to_[from].Add(to);
			from_[to].Add(from);
		}

		public long[] CalculateDistance(int startIndex, out bool existsNegativeCycle)
		{
			long[] distances = new long[count_];
			for (int i = 0; i < count_; i++) {
				if (i != startIndex) {
					distances[i] = INFINITY;
				}
			}

			existsNegativeCycle = false;
			for (int i = 0; i < count_; i++) {
				bool changes = false;
				foreach (var edge in edges_) {
					if (distances[edge.From] != INFINITY) {
						long newDistance = distances[edge.From] + edge.Cost;
						if (newDistance < distances[edge.To]) {
							changes = true;
							distances[edge.To] = newDistance;
						}
					}
				}

				if (i == count_ - 1) {
					existsNegativeCycle = changes;
				}
			}

			return distances;
		}

		public long CalculateDistance(int startIndex, int endIndex, out bool existsNegativeCycle)
		{
			long[] distances = new long[count_];
			for (int i = 0; i < count_; i++) {
				if (i != startIndex) {
					distances[i] = INFINITY;
				}
			}

			bool[] reachableFromStart = new bool[count_];
			bool[] reachableFromEnd = new bool[count_];
			DfsForTo(startIndex, reachableFromStart);
			DfsForFrom(endIndex, reachableFromEnd);

			bool[] enableds = new bool[count_];
			for (int i = 0; i < count_; i++) {
				enableds[i] = reachableFromStart[i] & reachableFromEnd[i];
			}

			existsNegativeCycle = false;
			for (int i = 0; i < count_; i++) {
				bool changes = false;
				foreach (var edge in edges_) {
					if (enableds[edge.From] == false || enableds[edge.To] == false) {
						continue;
					}

					if (distances[edge.From] != INFINITY) {
						long newDistance = distances[edge.From] + edge.Cost;
						if (newDistance < distances[edge.To]) {
							changes = true;
							distances[edge.To] = newDistance;
						}
					}
				}

				if (i == count_ - 1) {
					existsNegativeCycle = changes;
				}
			}

			return distances[endIndex];
		}

		private void DfsForTo(int index, bool[] reachableFromStart)
		{
			if (reachableFromStart[index]) {
				return;
			}

			reachableFromStart[index] = true;
			foreach (int next in to_[index]) {
				DfsForTo(next, reachableFromStart);
			}
		}

		private void DfsForFrom(int index, bool[] reachableFromEnd)
		{
			if (reachableFromEnd[index]) {
				return;
			}

			reachableFromEnd[index] = true;
			foreach (int next in from_[index]) {
				DfsForFrom(next, reachableFromEnd);
			}
		}

		private struct Edge
		{
			public int From;
			public int To;
			public long Cost;
		}
	}

	public class Scanner
	{
		private readonly char[] delimiter_ = new char[] { ' ' };
		private string[] buf_;
		private int index_;
		
		public Scanner()
		{
			buf_ = new string[0];
			index_ = 0;
		}

		public string Next()
		{
			if (index_ < buf_.Length) {
				return buf_[index_++];
			}

			string st = Console.ReadLine();
			while (st == "") {
				st = Console.ReadLine();
			}

			buf_ = st.Split(delimiter_, StringSplitOptions.RemoveEmptyEntries);
			if (buf_.Length == 0) {
				return Next();
			}

			index_ = 0;
			return buf_[index_++];
		}

		public int Int()
		{
			return int.Parse(Next());
		}
		public int[] ArrayInt(int N, int add = 0)
		{
			int[] Array = new int[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Int() + add;
			}
			return Array;
		}

		public long Long()
		{
			return long.Parse(Next());
		}

		public long[] ArrayLong(int N, long add = 0)
		{
			long[] Array = new long[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Long() + add;
			}
			return Array;
		}

		public double Double()
		{
			return double.Parse(Next());
		}

		public double[] ArrayDouble(int N, double add = 0)
		{
			double[] Array = new double[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Double() + add;
			}
			return Array;
		}
	}
}


Measured memory_bytes: 13792