#include <bits/stdc++.h>

using namespace std;
#define _for(i,j,N) for(int i = (j);i < (N);i++)
#define _rep(i,j,N) for(int i = (j);i <= (N);i++)
#define _dec(i,N,j) for(int i = (N-1);i >= (j);i--)
#define _rec(i,N,j) for(int i = (N);i >=(j);i--)
#define ALL(x) x.begin(),x.end()
#define MEM(a,n) memset(a,n,sizeof(a))
#define fst first
#define scd second
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

int get_int(){int x;scanf("%d",&x);return x;}
LL get_ll(){LL x;scanf("%lld",&x);return x;}
double get_db(){double x;scanf("%lf",&x);return x;}

template<typename T> int chmin(T &a,T &b){if(a > b){a = b;return 1;}else return 0;}
template<typename T> int chmax(T &a,T &b){if(a < b){a = b;return 1;}else return 0;}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& v) {_for(i,0,v.size()) os << v[i] << " ";return os;}
template<typename T>
ostream& operator<<(ostream& os,const set<T>& v){for(auto a:v) os << a <<" ";return os;}
template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& v){os << v.fst <<" "<<v.scd << " ";return os;}
template<typename T1,typename T2>
ostream& operator<<(ostream& os,const map<T1,T2>& v){for(auto a:v) cout << a << endl;return os;}

static const int dx[8] = { 1,  0, -1,  0,  1, -1,  1, -1};
static const int dy[8] = { 0,  1,  0, -1,  1, -1, -1,  1};
const double pi  = acos(-1.0);
const double eps = 1e-8;
const LL  INF  = 0x3f3f3f3f3f3f3f3f;
const int inf  = 0x3f3f3f3f;

const int maxn = 3000;

vector<int> G2[maxn];
int vis[maxn];

void dfs(int u){
    vis[u] = 1;
    for(auto a:G2[u]){
        int v = a;
        if(!vis[v]) dfs(v);
    }
}
struct Bellman_ford{
    int n,m;
    struct Edge{
        int from,to,dist;
        Edge(int from,int to,int dist):from(from),to(to),dist(dist){;}
    };
    vector<int> G[maxn];
    //判断进行松弛操作的次数
    int cnt[maxn];
    LL d[maxn];
    int p[maxn];
    //判断是否在queue里
    bool inq[maxn];
    vector<Edge> edges;

    void init(int n){
        this->n = n;
        edges.clear();
        _for(i,0,n) G[i].clear();
    }

    void add_edge(int from,int to,int dist){
        edges.push_back(Edge(from,to,dist));
        m = edges.size();
        G[from].push_back(m-1);
    }

    bool bellman_ford(int s){
        queue<int> Q;
        memset(inq, 0 ,sizeof(inq));
        memset(cnt,0,sizeof(cnt));
        _for(i,0,n) d[i] = INF;
        d[s] = 0;
        inq[s] = true;
        Q.push(s);

        while(!Q.empty()){
            int u = Q.front();Q.pop();
            inq[u] = false;
            for(int i = 0;i < G[u].size();i++){
                Edge& e = edges[G[u][i]];
                if(vis[e.to] && d[u] < INF && d[e.to] > d[u] + e.dist){
                    d[e.to] = d[u] + e.dist;
                    p[e.to] = G[u][i];
                    if(!inq[e.to]){
                        Q.push(e.to);
                        inq[e.to] = true;
                        if(++cnt[e.to] > n) return false;
                    }
                }
            }
        }
        return true;
    }
};




int main()
{
    int N,M,P;
    cin >> N >> M >> P;
    Bellman_ford BF;
    BF.init(N+1);

    _for(i,0,M){
        int u,v,w;
        cin >> u >> v >> w;
        BF.add_edge(u,v,- w + P);
        G2[v].PB(u);
    }
    MEM(vis,0);
    dfs(N);

    if(BF.bellman_ford(1)){
        if(!vis[1]){
            cout << -1 << endl;
            return 0;
        }

        LL ans = -BF.d[N];
        ans = max((LL)0,ans);
        cout << ans << endl;

    }else{
        cout << -1 << endl;
    }

    return 0;
}


Measured memory_bytes: 896