#include <algorithm>
#include <bits/stdc++.h>
#include <cassert>
#include <cstddef>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <limits>
#include <vector>

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef std::int_fast64_t i64;
typedef std::uint_fast64_t u64;
typedef std::int_fast32_t i32;
typedef std::uint_fast32_t u32;

namespace tools {
  template <typename T>
  void read(std::vector<T>& vector, const typename std::vector<T>::size_type size) {
    vector.reserve(size);
    std::copy_n(std::istream_iterator<T>(std::cin), size, std::back_inserter(vector));
  }

  template <typename T, std::size_t N>
  void read(std::array<T, N>& array) {
    std::copy_n(std::istream_iterator<T>(std::cin), N, array.begin());
  }
}

#endif

// lib/bellman_ford.hpp
#ifndef BELLMAN_FORD_HPP
#define BELLMAN_FORD_HPP


/*
usage:

tools::bellman_ford<std::int_fast64_t> bf(node_count);
bf.add_edge(from_node, to_node, cost);
const tools::bellman_ford<std::int_fast64_t>::result result = bf.calc(start_node);
if (result.found_negative_cycle) {
  // ...
} else {
  for (const std::int_fast64_t& distance : result.distances) {
    // ...
  }
}
*/

namespace tools {
  template <typename T>
  class bellman_ford {
  private:
    class edge {
    public:
      std::size_t from;
      std::size_t to;
      T distance;
      edge(const std::size_t from, const std::size_t to, const T distance) :
        from(from),
        to(to),
        distance(distance) {
      }
    };

    std::size_t m_node_count;
    std::vector<edge> edges;

    static T safe_sum(const T x, const T y) {
      return x < INF && y < INF ? x + y : INF;
    }

  public:
    static constexpr T INF = std::numeric_limits<T>::max();
    static constexpr std::size_t NONE = std::numeric_limits<std::size_t>::max();

    class result {
    public:
      std::vector<T> distances;
      std::vector<std::size_t> prev_nodes;
      bool found_negative_cycle;
      result(const std::size_t node_count) :
        distances(node_count, INF),
        prev_nodes(node_count, NONE),
        found_negative_cycle(false) {
      }
    };

    bellman_ford(const std::size_t node_count) :
      m_node_count(node_count),
      edges() {
    }

    std::size_t node_count() const {
      return this->m_node_count;
    }

    void add_edge(const std::size_t from, const std::size_t to, const T distance) {
      this->edges.emplace_back(from, to, distance);
    }

    result calc(const std::size_t start_node) const {
      assert(start_node < this->m_node_count);
      result result(this->m_node_count);
      result.distances[start_node] = 0;
      for (std::size_t i = 0; i < this->m_node_count - 1; ++i) {
        for (const edge& edge : this->edges) {
          if (safe_sum(result.distances[edge.from], edge.distance) < result.distances[edge.to]) {
            result.distances[edge.to] = safe_sum(result.distances[edge.from], edge.distance);
            result.prev_nodes[edge.to] = edge.from;
          }
        }
      }
      result.found_negative_cycle = false;
      for (std::size_t i = 0; i < this->m_node_count; ++i) {
        for (const edge& edge : this->edges) {
          if (safe_sum(result.distances[edge.from], edge.distance) < result.distances[edge.to]) {
            result.distances[edge.to] = safe_sum(result.distances[edge.from], edge.distance);
            result.prev_nodes[edge.to] = edge.from;
            if (edge.to == this->m_node_count - 1) {
              result.found_negative_cycle = true;
              break;
            }
          }
        }
      }
      return result;
    }
  };
}

#endif

// main.cpp

int main() {
  i64 N, M, P;
  std::cin >> N >> M >> P;

  tools::bellman_ford<i64> bf(N);
  for (i64 i = 0; i < M; ++i) {
    i64 A_i, B_i, C_i;
    std::cin >> A_i >> B_i >> C_i;
    --A_i;
    --B_i;
    bf.add_edge(A_i, B_i, -C_i + P);
  }
  const tools::bellman_ford<i64>::result result = bf.calc(0);
  if (result.found_negative_cycle) {
    std::cout << -1 << std::endl;
  } else {
    std::cout << std::max<i64>(-result.distances.back(), 0) << std::endl;
  }
  return 0;
}

Measured memory_bytes: 512