#include<cstdio>
#include<cstring>
#include<iostream>
#define m(s,t) memset(s,t,sizeof s)
#define R register
#define inf 2139062143
using namespace std;
const int N=2510;
const int M=3e6+10;
struct node{
int v,next,cap,cost;
}e[M];int tot=1;
int n,m,S,T,ans,head[N],pree[N],prev[N],flow[N],dis[N],q[N*10];
bool vis[N];
void add(int x,int y,int a,int b){
e[++tot].v=y;e[tot].cap=a;e[tot].cost=b;e[tot].next=head[x];head[x]=tot;
}
void ins(int x,int y,int a,int b){
add(x,y,a,b);add(y,x,0,-b);
}
void Cl(){
tot=1;ans=0;
m(head,0);m(pree,0);m(prev,0);m(flow,0);
}
bool spfa(){
m(vis,0);m(dis,127);
int h=0,t=1;
q[t]=S;dis[S]=0;vis[S]=1;flow[S]=inf;
while(h!=t){
int x=q[++h];
vis[x]=0;
for(int i=head[x];i;i=e[i].next){
int v=e[i].v,cap=e[i].cap,cost=e[i].cost;
if(cap>0&&dis[v]>dis[x]+cost){
dis[v]=dis[x]+cost;
prev[v]=x;pree[v]=i;
flow[v]=min(flow[x],cap);
if(!vis[v]){
vis[v]=1;
q[++t]=v;
}
}
}
}
return dis[T]<inf;
}
void work(){
for(int i=T;i!=S;i=prev[i]){
e[pree[i]].cap-=flow[T];
e[pree[i]^1].cap+=flow[T];
}
ans+=flow[T]*dis[T];
}
int main(){
scanf("%d%d",&n,&m);S=0,T=n*2+1;
for(int i=1,w;i<=n;i++){
scanf("%d",&w);
ins(0,i,1,0);
ins(0,i+n,1,w);
ins(i+n,T,1,0);
}
for(int i=1,u,v,w;i<=m;i++){
scanf("%d%d%d",&u,&v,&w);
if(u>v) swap(u,v);
ins(u,v+n,1,w);
}
while(spfa()) work();
printf("%d",ans);
return 0;
}