#include<bits/stdc++.h>
using namespace std;
const int N=200005,M=2000005,INF=100000000;
int n,m,S,T;
int p[N];
struct oppo{
int to,nex,s;
}rod[M];
int head[N],tot;
void add(int from,int to,int s)
{
rod[tot].to=to;
rod[tot].nex=head[from];
rod[tot].s=s;
head[from]=tot++;
}
void link(int from,int to,int s)
{
add(from,to,s);
add(to,from,0);
}
int d[N],cur[N];
bool bfs()
{
queue<int> v;
memset(d,-1,sizeof(d));
d[S]=0;cur[S]=head[S];
v.push(S);
while(v.size())
{
int lxl=v.front();v.pop();
for(int i=head[lxl];~i;i=rod[i].nex)
{
int to=rod[i].to;
if(d[to]==-1&&rod[i].s)
{
d[to]=d[lxl]+1;
cur[to]=head[to];
if(to==T) return 1;
v.push(to);
}
}
}
return 0;
}
int find(int x,int low)
{
if(x==T) return low;
int all=0;
for(int i=cur[x];~i;i=rod[i].nex)
{
cur[x]=i;
int to=rod[i].to;
if(d[to]==d[x]+1&&rod[i].s)
{
int t=find(to,min(rod[i].s,low-all));
if(!t) d[to]=-1;
rod[i].s-=t;
rod[i^1].s+=t;
all+=t;
}
if(all==low) break;
}
return all;
}
int dinic()
{
int ans=0,r;
while(bfs()) while(r=find(S,INF)) ans+=r;
return ans;
}
int ans;
int main()
{
memset(head,-1,sizeof(head));
cin>>n>>m;
S=0,T=n+m+1;
for(int i=1;i<=n;i++){
scanf("%d",&p[i]);
link(i,T,p[i]);
}
for(int i=1;i<=m;i++){
int a,b,c;
scanf("%d%d%d",&a,&b,&c);
link(n+i,a,INF);
link(n+i,b,INF);
link(S,n+i,c);
ans+=c;
}
cout<<ans-dinic()<<"\n";
return 0;
}