#include<fstream>
#include<cstdilb>
using namespace std;
struct f
{
int a;
int b,
int l;
}y[50001];
int cmp(const void *a,const void *b)
{
struct f *c=(struct f *)a;
struct f *d=(struct f *)b;
return c->l-d->l;
}
int main(void)
{
ifstream fin("cost.in");
ofstream fout("cost.out");
int n,m,u,v,s;
fin>>n>>m>>u>>v>>s;
int p[10001];
int i;
for(i=1;i<=n;i++)
fin>>p[i];
for(i=0;i<m;i++)
fin>>y[i][0]>>y[i][1]>>y[i][2];
qsort(y,m-1,sizeof(y[0]),cmp);
fout<<"-1";
fin.close();
fout.close();
return 0;
}