#include<bits/stdc++.h>
#include<string.h>
 
typedef long long int ll;
#define all(x) (x).begin(), (x).end()
 
using namespace std;

int nxt() {
    int x;
    cin >> x;
    return x;
}

ll nxtl(){
    ll x;
    cin>>x;
    return x;
}
 
void SieveOfEratosthenes(int n,vector <int> &primes) 
{ 
    // Create a boolean array "prime[0..n]" and initialize 
    // all entries it as true. A value in prime[i] will 
    // finally be false if i is Not a prime, else true. 
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            // Update all multiples of p greater than or  
            // equal to the square of it 
            // numbers which are multiple of p and are 
            // less than p^2 are already been marked.  
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
  
    // Print all prime numbers 
    for (int p=2; p<=n; p++) 
       if (prime[p]) 
          primes.push_back(p);
} 
 
ll max(ll a,ll b)
{
    if(a>b)
        return a;
    return b;
}
 
ll power(ll x, ll y,ll mod) 
{ 
    ll temp; 
    if( y == 0) 
        return 1; 
    temp = power(x, y/2,mod); 
    if (y%2 == 0) 
        return (temp*temp)%mod; 
    else
        return (((x*temp)%mod)*temp)%mod; 
}

vector <map <ll,ll> > g;
vector <pair<int,pair<int,int> > > edges;
vector <vector <ll> > g2;
set <ll> reach;
set <ll> current;
vector <ll> parent;
ll n,p,m;
bool f;
vector <ll> ans;

void bfs(ll s);ll dfs(vector <bool> &visited,ll s);

vector <ll> dist;

// The main function that finds shortest distances from src to 
// all other vertices using Bellman-Ford algorithm.  The function 
// also detects negative weight cycle 
void BellmanFord(int src) 
{ 
    
  
    // Step 1: Initialize distances from src to all other vertices 
    // as INFINITE 
    for (int i = 1; i <= n; i++) 
        dist[i] = 1e16; 
    dist[src] = 0; 
  
    // Step 2: Relax all edges |V| - 1 times. A simple shortest 
    // path from src to any other vertex can have at-most |V| - 1 
    // edges 
    for (int i = 1; i <= n - 1; i++) { 
        for (int j = 0; j < m; j++) { 
            int u = edges[j].first; 
            int v = edges[j].second.first; 
            int weight = edges[j].second.second;
            //if(u==src)
            //cout<<u<<" "<<v<<" "<<weight<<endl;
            if (dist[u] != 1e16 && dist[u] + weight < dist[v]) 
                dist[v] = dist[u] + weight; 
        } 
    } 

    // Step 3: check for negative-weight cycles.  The above step 
    // guarantees shortest distances if graph doesn't contain 
    // negative weight cycle.  If we get a shorter path, then there 
    // is a cycle. 
    ll x=dist[n];
    for (int i = 1; i <= n - 1; i++) { 
        for (int j = 0; j < m; j++) { 
            int u = edges[j].first; 
            int v = edges[j].second.first; 
            int weight = edges[j].second.second;
            //if(u==src)
            //cout<<u<<" "<<v<<" "<<weight<<endl;
            if (dist[u] != 1e16 && dist[u] + weight < dist[v]) 
                dist[v] = dist[u] + weight; 
        } 
    } 
   
    if(dist[n]<x)
    {
        f=0;
    }
  
    
} 

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    n=nxt();
    m=nxt();
    p=nxt();
    map <ll,ll> r;
    vector <ll> r2;
    g.resize(n+1,r);
    g2.resize(n+1,r2);
    parent.resize(n+1);
    parent[1]=0;
    edges.resize(m);
    for(ll i=0;i<m;i++)
    {
        ll a=nxt(),b=nxt(),c=nxt();
        g[a][b]=max(g[a][b],c);
        g2[b].push_back(a);
        edges[i]={a,{b,-(c-p)}};
        //if(a==1)
        //cout<<a<<" "<<b<<" "<<c<<endl; 
    }

    bfs(n);
    f=1;
    vector <bool> visited;
    visited.resize(n+1,0);
    //cout<<"c1"<<endl;
    ans.resize(n+1);
    //ll test=dfs(visited,1);
    
    dfs(visited,1);
    dist.resize(n+1);
    BellmanFord(1);
    if(!f)
    {
        cout<<"-1\n";
        return 0;
    }
    //for(int i=1;i<=n;i++)
       // cout<<dist[i]<<" ";
    //cout<<endl;
    cout<<max(0,-dist[n])<<endl;
    
    
    return 0;   
}

void bfs(ll s)
{
    vector <bool> visited;
    visited.resize(n+1,0);
    queue <ll> q;
    visited[s]=1;
    q.push(s);
    reach.insert(s);
    while(q.size())
    {
        ll x=q.front();
        q.pop();
        for(auto i:g2[x])
        {
            if(!visited[i])
            {
                visited[i]=1;
                reach.insert(i);
                q.push(i);
            }
        }

    }
}

ll dfs(vector <bool> &visited,ll s)
{//cout<<s<<endl;
    ll val;
    if(s!=n)
        val=INT_MIN;
    else
        val=0;
    current.insert(s);
    visited[s]=1;
    for(auto it=g[s].begin();it!=g[s].end();it++)
    {
        if(!visited[it->first])
        {
            parent[it->first]=s;
            ll ret=dfs(visited,it->first);
            //cout<<s<<" "<<it->first<<" "<<ret<<endl;
            if(ret!=INT_MIN)
                val=max(val,ret+it->second-p);
        }
        else
        {
            if(current.count(it->first))
            {
                ll sum=it->second;
                ll lim=it->first;
                ll cur=s;
                ll num=1;
                bool f2=0;
                if(reach.count(cur))
                    f2=1;
                while(cur!=lim)
                {//cout<<"came"<<endl;
                    ll prev=cur;
                    cur=parent[cur];
                    if(reach.count(cur))
                        f2=1;
                    num++;
                    sum+=g[cur][prev];
                }
                
                if(f2&&sum>p*num)
                    f=0;
            }
            else
            {
                if(ans[it->first]!=INT_MIN)
                    val=max(val,ans[it->first]+it->second-p);
            }
        }

    }
    current.erase(s);
    ans[s]=val;
    return val;
}


 
 


Measured memory_bytes: 1280