#include <cstdio>
#include <cstring>
#include <queue>
using namespace std;
typedef pair<int,int> pii; typedef queue<int> qi; typedef vector<pii> vii; typedef long long ll;
#define fi first
#define se second
#define pb push_back
const ll inf = 4485090715960753727;
int N,M,P,vis[2501]; bool inq[2501]; qi q; vii adj[2501]; ll dis[2501];
int main() {
    scanf("%d%d%d",&N,&M,&P);
    for (int i = 0,A,B,C;i < M;i++) scanf("%d%d%d",&A,&B,&C),C-=P,adj[A].pb({B,C});
    memset(dis,-0x3f,sizeof dis); dis[1] = 0; q.push(1); inq[1] = 1;
    while (!q.empty()) {
        int cur = q.front(); q.pop(); inq[cur] = 0; vis[cur]++;
        if (vis[cur] > N<<1) break;
        for (pii nxt : adj[cur]) if (dis[cur]+nxt.se > dis[nxt.fi]) {
            dis[nxt.fi] = dis[cur]+nxt.se;
            if (!inq[nxt.fi]) q.push(nxt.fi),inq[nxt.fi] = 1;
        }
    }
    if (vis[N] >= N || dis[N] == -inf) printf("-1\n");
    else printf("%lld\n",max(0LL,dis[N]));
}
