//#define _GLIBCXX_DEBUG

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

constexpr ll INF = 1e16;
constexpr ll MOD = 1000000007;

// modint: mod 計算を int を扱うように扱える構造体
template<int MOD> struct Fp {
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
        if (val < 0) v += MOD;
    }
    constexpr int getmod() { return MOD; }
    constexpr Fp operator - () const noexcept {
        return val ? MOD - val : 0;
    }
    constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp& operator += (const Fp& r) noexcept {
        val += r.val;
        if (val >= MOD) val -= MOD;
        return *this;
    }
    constexpr Fp& operator -= (const Fp& r) noexcept {
        val -= r.val;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr Fp& operator *= (const Fp& r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr Fp& operator /= (const Fp& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr bool operator == (const Fp& r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator != (const Fp& r) const noexcept {
        return this->val != r.val;
    }
    friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {
        return os << x.val;
    }
    friend constexpr istream& operator >> (istream &is, Fp<MOD>& x) noexcept {
        return is >> x.val;
    }
    friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
        if (n == 0) return 1;
        auto t = modpow(a, n / 2);
        t = t * t;
        if (n & 1) t = t * a;
        return t;
    }
};

using mint = Fp<((int)MOD)>;

#define rep(i, N) for(ll i=0; i<(N); ++i)

template<class T> inline bool chmax(T& a, T b) { if(a < b) { a = b; return 1; } else { return 0; }}
template<class T> inline bool chmin(T& a, T b) { if(a > b) { a = b; return 1; } else { return 0; }}


ll max(ll a, ll b) {return a < b ? b : a; }
ll min(ll a, ll b) {return a > b ? b : a; }
double maxf(double a, double b) { return a < b ? b : a; }

template<typename T> inline string toString(const T &a) {
  ostringstream oss; oss << a; return oss.str();
}

ll gcd(ll x, ll y) { return x % y ? gcd(y, x % y) : y; }
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }

struct hash_pair {
  template <class T1, class T2>
  size_t operator()(const pair<T1, T2>& p) const
  {
    auto hash1 = hash<T1>{}(p.first);
    auto hash2 = hash<T2>{}(p.second);
    return hash1 ^ hash2;
  }
};

//lower_bound: equal or greater than
//upper_bound: greater than
//Remember "upper_bound is greater"


template <typename T>
unordered_set<T> unionset(unordered_set<T>& t1, unordered_set<T>& t2) {
  unordered_set<T> t3;
  
  for(T e : t1) {
    if(t2.find(e) != t2.end()) {
      t3.emplace(e);
    }
  }
  
  return t3;
}

//DFSを使用し，curから到達可能な頂点集合をseenに返す
void dfsReach(vector<vector<int>>& pointf, unordered_set<int>& seen, int cur) {
  for(int next : pointf[cur]) {
    if(seen.find(next) == seen.end()) {
      seen.emplace(next);
      dfsReach(pointf, seen, next);
    }
  }
}


//BFSで
unordered_set<int> reach(int N, vector<pair<pair<int, int>, int>>& edges) {
  //頂点から出る辺
  vector<vector<int>> pointf(N+1, vector<int>());
  vector<vector<int>> pointr(N+1, vector<int>());
  for(auto pr : edges) {
    pointf[pr.first.first].push_back(pr.first.second);
    pointr[pr.first.second].push_back(pr.first.first);
  }
  
  unordered_set<int> r1;
  dfsReach(pointf, r1, 1);
  unordered_set<int> rn;
  dfsReach(pointr, rn, N);
  
  return unionset(r1, rn); 
}

int main() {
  int N;
  int M;
  int P;
  cin >> N >> M >> P;
  // vector<vector<pair<int, int>>> ve(N + 1, vector<pair<int, int>>());
  vector<pair<pair<int, int>, int>> edges;
  rep(i, M) {
    int A, B, C;
    cin >> A >> B >> C;
    // ve[A].push_back(make_pair(B, C - P));
    edges.push_back(make_pair(make_pair(A, B), -(C - P)));
  }
  
  //経路の値が負になったときは0にする
  //ベルマンフォード法で最短経路（*-1してある）
  //頂点は1-baseなので注意
  //for each vertex
  vector<pair<ll, int>> vd(N + 1);
  for(int i = 1; i<= N; ++i) {
    vd[i] = make_pair(INF, -1);
  }
  vd[1] = make_pair(0, -1);
  
  for(int i = 1; i<= N; ++i) {
    for(int j = 0; j < edges.size(); ++j) {
      auto pr = edges[j];
      if(vd[pr.first.first].first + pr.second < vd[pr.first.second].first) {
        vd[pr.first.second] =
          make_pair(vd[pr.first.first].first + pr.second, pr.first.first);
      }
    }
  }
  
  //経路に現れる点を取得
  unordered_set<int> seen;
  int curv = N;
  while(curv != 1) {
    seen.emplace(curv);
    curv = vd[curv].second;
    if(curv == -1 || seen.find(curv) != seen.end()) {
      cout << "-1" << endl;
      return 0;
    }
  }
  seen.emplace(1);
  
  // //負閉路検出 => 嘘解法
  // for(int j = 0; j < edges.size(); ++j) {
  //   auto pr = edges[j];
  //   if(seen.find(pr.first.first) != seen.end() && seen.find(pr.first.second) != seen.end() && vd[pr.first.first].first + pr.second < vd[pr.first.second].first) {
  //     cout << "-1" << endl;
  //     return 0;
  //   }
  // }
  
  //頂点1かつNから到達可能な範囲
  unordered_set<int> reach1 = reach(N, edges);
  //NM回回して更新するか
  for(int i = 1; i<= N; ++i) {
    for(int j = 0; j < edges.size(); ++j) {
      auto pr = edges[j];
      if(vd[pr.first.first].first + pr.second < vd[pr.first.second].first) {
        if(reach1.find(pr.first.first) != reach1.end() && reach1.find(pr.first.second) != reach1.end()) {
          //関係のある閉路
          cout << "-1" << endl;
          return 0;  
        }
        
        vd[pr.first.second] =
          make_pair(vd[pr.first.first].first + pr.second, pr.first.first);
      }
    }
  }
  
  //経路
  ll sum = vd[N].first;
  sum = -sum;
  
  if(sum < 0) sum = 0;
  
  cout << sum << endl;
}


Measured memory_bytes: 1152