#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
using namespace std;
ifstream fin("algola.in");
ofstream fout("algola.out");
#define MAX 5100
typedef vector <int> :: iterator iter;
vector <int> G[MAX];
queue <int> Q;
char C[MAX][MAX], F[MAX][MAX];
int n, viz[MAX], dad[MAX], sum, x[MAX], y[MAX], c[MAX], flow, time;
int node(int x, int y)
{
return x + y * n;
}
void make_edge(int x, int y, int z)
{
C[x][y] = z;
G[x].push_back(y);
G[y].push_back(x);
}
bool bf(int time)
{
int i, nod;
for(i = 0 ; i < MAX ; i++)
viz[i] = 0;
while(Q.size())
Q.pop();
Q.push(0);
viz[0] = 1;
while(Q.size())
{
nod = Q.front();
Q.pop();
for(iter it = G[nod].begin() ; it != G[nod].end() ; it++)
{
if(!viz[*it] && F[nod][*it] < C[nod][*it])
{
viz[*it] = 1;
Q.push(*it);
dad[*it] = nod;
if(*it == node(1, 0))
return 1;
}
}
}
return 0;
}
int main()
{
dad[0] = -1;
int m, i, a, f, nod;
sum = 0;
fin >> n >> m;
for(i = 1 ; i <= n ; i++)
{
fin >> a;
sum += a;
make_edge(0, node(i, 0), a);
}
for(i = 1 ; i <= m ; i++)
{
fin >> x[i] >> y[i] >> c[i];
}
flow = 0;
for(time = 0 ; time <= 100 ; time++)
{
if(time)
{
for(i = 1 ; i <= n ; i++)
{
make_edge(node(i, time - 1), node(i, time), 50);
}
for(i = 1 ; i <= m ; i++)
{
make_edge(node(x[i], time - 1), node(y[i], time), c[i]);
make_edge(node(y[i], time - 1), node(x[i], time), c[i]);
}
make_edge(node(1, time), node(1, 0), 50);
}
while(bf(time))
{
f = (1<<29);
for(nod = node(1, 0) ; dad[nod] != -1 ; nod = dad[nod])
{
f = min(f, C[dad[nod]][nod] - F[dad[nod]][nod]);
}
for(nod = node(1, 0) ; dad[nod] != -1 ; nod = dad[nod])
{
F[dad[nod]][nod] += f;
F[nod][dad[nod]] -= f;
}
flow += f;
}
if(flow == sum)
{
fout << time << "\n";
/* for(i = 0 ; i <= node(n, time) ; i++)
{
for(int j = 0 ; j <= node(n, time) ; j++)
cout << (int)C[i][j] << " ";
cout << "\n";
}
cout << "\n";
for(i = 0 ; i <= node(n, time) ; i++)
{
for(int j = 0 ; j <= node(n, time) ; j++)
cout << (int)F[i][j] << " ";
cout << "\n";
}*/
return 0;
}
}
}