#include <bits/stdc++.h>
using namespace std;
const int N = 1e4;
struct Edge
{
int to, w;
};
struct Node
{
int id, dis;
bool operator< (const Node b) const {return dis < b.dis;}
};
int n, m, b;
vector < Edge > graph[N];
int f[N];
bool vis[N]{};
int dis[N]{};
bool check(int mid)
{
memset(dis, 0x3f, sizeof dis);
dis[1] = 0;
priority_queue < Node > q;
q.push(Node{1, 0});
while (!q.empty()){
int u = q.top().id;
int d = q.top().dis;
q.pop();
for (int v = 0; v < graph[u].size(); v++){
if (f[graph[u][v].to] > mid)
continue;
if (dis[graph[u][v].to] > dis[u] + d){
dis[graph[u][v].to] = dis[u] + d;
q.push(Node{graph[u][v].to, dis[graph[u][v].to]});
}
}
}
return dis[n] <= b;
}
int main()
{
cin >> n >> m >> b;
for (int i = 1; i <= n; i++)
cin >> f[i];
for (int i = 1; i <= m; i++){
int a, b, c;
cin >> a >> b >> c;
graph[a].push_back({b, c});
graph[b].push_back({a, c});
}
int l = max(f[1], f[n]), r = 1e9 + 1;
while (l < r){
int mid = l + r >> 1;
if (check(mid))
r = mid;
else
l = mid + 1;
}check(l);
if (dis[n] > b)
cout << "AFK" << endl;
else
cout << l << endl;
}