#include "bits/stdc++.h"
using namespace std;

using Info = bitset<101>;

vector<int> make_dag(vector<vector<int>> edges) {
	const int N = edges.size();
	vector<int> parnum(N);
	for (auto row : edges)for (auto col : row)parnum[col]++;

	queue<int> q;
	vector<int> res;
	for (int i = 0; i < N; i++)if (parnum[i] == 0)q.push(i);

	while (!q.empty()) {
		int v = q.front(); q.pop();
		for (auto u : edges[v]) {
			parnum[u]--;
			if (parnum[u] == 0) {
				q.push(u);
			}
		}
		res.push_back(v);
	}
	return res;
}

int main() {
	int V, E, w;
	cin >> V >> E >> w;
	vector<map<int, int>> edges(V);
	vector<vector<int>> parents(V), fordag(V);

	for (int i = 0; i < E; i++) {
		int s, t, c;
		cin >> s >> t >> c;
		edges[s][t] = c;
		parents[t].push_back(s);
		fordag[s].push_back(t);
	}

	// dag
	vector<int> dag = make_dag(fordag);

	// way
	vector<Info> res(V);
	for (auto& pos : dag) {
		for (int& parent : parents[pos]) {
			int len = edges[parent][pos];
			for (int i = 0; i < 101; i++) if (res[parent][i]) {
				int score = i + len;
				if (score + w < 0)res[pos][score] = true;
			}
			if (len + w < 0)res[pos][len] = true;
		}
	}

	int ans = -1;
	for (const auto& row : res)
		for (int i = 0; i < 101; i++)if (row[i])ans = max(ans, i);

	cout << (ans == -1 ? "NA" : to_string(ans + w)) << endl;
	return 0;
}
