#include<bits/stdc++.h>
using namespace std;
int n,m,hp;
struct Node{
int to,val;
};
int w[10001];
vector<Node>a[10001];
bool js[10001];
bool bj=0;
struct ycy{
int w,p,mid;
}b[100000];
int tot=0;
void push_down(int x){
if(x*2+1<=tot&&b[x*2+1].w<b[x*2].w&&b[x*2+1].w<b[x].w){
swap(b[x],b[x*2+1]);
push_down(x*2+1);
}
else if(x*2+1<=tot&&b[x*2].w<b[x].w){
swap(b[x*2],b[x]);
push_down(x*2);
}
else if(x*2==tot&&b[x*2].w<b[x].w){
swap(b[x*2],b[x]);
push_down(x*2);
}
}
void push_up(int x){
if(x!=1&&b[x].w<b[x/2].w){
swap(b[x],b[x/2]);
push_up(x/2);
}
}
void bfs(int val,int p,int mid){
if(p==n&&val<=hp){
bj=1;
}
if(js[p]){
return;
}
js[p]=1;
if(w[p]>mid){
return;
}
for(auto it:a[p]){
if(!js[it.to]&&it.val<=mid){
b[++tot]={val+it.val,it.to,mid};
push_up(tot);
}
}
}
int main(){
scanf("%d%d%d",&n,&m,&hp);
for(int i=1;i<=n;i++){
scanf("%d",&w[i]);
}
for(int i=1;i<=m;i++){
int u,v,val;
scanf("%d%d%d",&u,&v,&val);
a[u].push_back({v,val});
a[v].push_back({u,val});
}
long long ans;
long long l=0,r=1e9;
while(l<=r){
bj=0;
long long mid=l+r>>1;
for(int i=1;i<=n;i++){
js[i]=0;
}
b[++tot]={0,1,mid};
while(tot){
bfs(b[1].w,b[1].p,b[1].mid);
swap(b[1],b[tot]);
tot--;
push_down(1);
}
if(bj){
r=mid-1;
ans=mid;
bj=1;
}
else{
l=mid+1;
ans=mid+1;
}
}
if(!bj){
printf("AFK");
return 0;
}
printf("%lld",ans);
return 0;
}