#include<map>
#include<cmath>
#include<queue>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define inf 1000000007
#define ll long long
#define N 400010
inline int rd()
{
int x=0,f=1;char ch=getchar();
while(ch<‘0‘||ch>‘9‘){if(ch==‘-‘)f=-1;ch=getchar();}
while(ch>=‘0‘&&ch<=‘9‘){x=x*10+ch-‘0‘;ch=getchar();}
return x*f;
}
int S,T;
int lj[N],fro[N],to[N],cnt=1,v[N],cur[N];
inline void add(int a,int b,int c){fro[++cnt]=lj[a];to[cnt]=b;v[cnt]=c;lj[a]=cnt;}
inline void ins(int a,int b,int c){add(a,b,c);add(b,a,0);}
int n,m;
ll sum;
int dis[N],q[N],h,t;
bool bfs()
{
memset(dis,0,sizeof(dis));
dis[0]=h=t=1;q[1]=0;
int tp;
while(h<=t)
{
tp=q[h++];
for(int i=lj[tp];i;i=fro[i])
{
if(!dis[to[i]]&&v[i])
{
dis[to[i]]=dis[tp]+1;
q[++t]=to[i];
}
}
}
return dis[T]?1:0;
}
int dfs(int x,int p)
{
if(x==T) return p;
int tp,res=0;
for(int &i=cur[x];i;i=fro[i])
{
if(v[i]&&dis[to[i]]==dis[x]+1)
{
tp=dfs(to[i],min(p-res,v[i]));
v[i]-=tp;v[i^1]+=tp;
res+=tp;
if(res==p) return p;
}
}
if(res==0) dis[x]=0;
return res;
}
int dinic()
{
int ans=0;
while(bfs())
{
for(int i=0;i<=T;i++) cur[i]=lj[i];
ans+=dfs(0,inf);
}
return ans;
}
int main()
{
n=rd();m=rd();T=n+m+1;
int x,y,z;
for(int i=1;i<=n;i++){x=rd();ins(m+i,T,x);}
for(int i=1;i<=m;i++)
{
x=rd();y=rd();z=rd();
sum+=z;ins(0,i,z);
ins(i,m+x,inf);
ins(i,m+y,inf);
}
printf("%lld\n",sum-dinic());
return 0;
}