#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Edge = pair<int, int>;
using Graph = vector<vector<Edge>>;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const ll nmax = 8;
const ll INF = 1e9;
bool graph[nmax][nmax];
vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
void warshall_floyd(ll n)
{
    for (size_t i = 0; i < n; i++)
    {
        for (size_t j = 0; j < n; j++)
        {
            for (size_t k = 0; k < n; k++)
            {
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
}

class UnionFind
{
public:
    vector<ll> Parent;

    UnionFind(ll N)
    {
        Parent = vector<ll>(N, -1);
    }
    ll find(ll A)
    {
        if (Parent[A] < 0)
            return A;
        return Parent[A] = find(Parent[A]);
    }

    ll size(ll A)
    {
        return -Parent[find(A)];
    }

    bool Union(ll A, ll B)
    {
        A = find(A);
        B = find(B);
        if (A == B)
        {
            return false;
        }
        if (size(A) < size(B))
            swap(A, B);

        Parent[A] += Parent[B];
        Parent[B] = A;

        return true;
    }
};

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

ll lcm(ll a, ll b)
{
    ll g = gcd(a, b);
    return a / g * b;
}

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}

ll powMod(ll a, ll p)
{
    if (p == 0)
    {
        return 1;
    }
    else if (p % 2 == 0)
    {
        ll half = powMod(a, p / 2);
        return mulMod(half, half);
    }
    else
    {
        return mulMod(powMod(a, p - 1), a);
    }
}

ll ceil(ll a, ll b)
{
    return (a + b - 1) / b;
}

// 深さ優先探索
vector<int> to[2505];
vector<int> reverseto[2505];
bool reachableFrom1[2505];
bool reachableToN[2505];
bool ok[2505];
void dfs(int v)
{
    if (reachableFrom1[v])
        return;
    reachableFrom1[v] = true;

    for (auto &&i : to[v])
    {
        dfs(i);
    }
}

void rdfs(int v)
{
    if (reachableToN[v])
        return;
    reachableToN[v] = true;

    for (auto &&i : reverseto[v])
    {
        rdfs(i);
    }
}

int main()
{
    int n, m, p;
    cin >> n >> m >> p;
    vector<tuple<int, int, int>> edges;
    for (int i = 0; i < m; i++)
    {
        int a, b, c;
        cin >> a >> b >> c;
        --a;
        --b;
        c -= p;
        c = -c;
        edges.emplace_back(a, b, c);
        to[a].push_back(b);
        reverseto[b].push_back(a);
    }



    dfs(0);
    rdfs(n - 1);
    for (int i = 0; i < n; i++)
    {
        ok[i] = reachableFrom1[i] & reachableToN[i];
    }

    { // bellman-ford
        vector<int> dist(n, 1001001001);
        dist[0] = 0;
        bool upd = true;
        int step = 0;
        while (upd)
        {
            upd = false;
            for (int i = 0; i < m; i++)
            {
                int a, b, c;
                tie(a, b, c) = edges[i];
                if (!ok[a])
                    continue;
                if (!ok[b])
                    continue;
                int newD = dist[a] + c;
                if (newD < dist[b])
                {
                    upd = true;
                    dist[b] = newD;
                }
            }
            step++;
            if (step > n)
            {
                cout << -1 << endl;
                return 0;
            }
        }
        int ans = -dist[n-1];
        cout << max(0,ans) << endl;
    }

    return 0;
}


Measured memory_bytes: 640