#include <iostream>
#include <string>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <ctime>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>
#include <cmath>
#include <assert.h>
#include <stack>
using namespace std;
#define vi vector<int>
#define mod 1000000007
#define inf 1000000007
#define ll long long
#define DBG(x) cerr<< (#x) <<"="<<x<<"\n";
template <class T> void add(int &a,T b){a=(a+b)%mod;}
inline ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
int getNext(vector<int>& visited,vector<int>& path) {
int minv = inf,index = -1;
for(int i=1;i<path.size();++i) {
if(path[i]<minv&&visited[i]==0) {
minv = path[i];
index = i;
}
}
return index;
}
void Dijkstra(vector<vector<int>>& G,vector<int>& path,int x) {
vector<int> visited(G.size(),0);
for(int i=1;i<G.size();++i) {
int next = getNext(visited,path);
if(next==-1) return;
visited[next] = 1;
for(int j=1;j<G.size();++j) {
if(G[next][j]) {
if(path[next]+1<path[j])
path[j] = path[next] + 1;
}
}
}
return;
}
int main() {
int N,M,W;
cin >> N >> M >> W;
vector<vector<int>> G(N+1,vector<int>(N+1,0));
for(int i=0;i<M;++i) {
int a,b,c;
cin >> a >> b >> c;
if(c>=W) {
G[a][b] = 1;
G[b][a] = 1;
}
}
vector<int> path(N+1,inf);
path[1] = 0;
Dijkstra(G,path,1);
if(path[N]==inf)
cout << -1 << endl;
else
cout << path[N] << endl;
return 0;
}