#include <bits/stdc++.h>
using namespace std;

#define fo(i, x, y) for (int i = (x); i <= (y); ++i)
#define fd(i, x, y) for (int i = (x); i >= (y); --i)

const int maxn = 2e5 + 5;

struct edge{int to, w; edge *nxt;}*arc1[maxn], *arc2[maxn], pool[maxn << 2], *pt = pool;
int n, m;
int ans[maxn];
bool vis[maxn];

int getint()
{
	char ch;
	int res = 0, p;
	while (!isdigit(ch = getchar()) && (ch ^ '-'));
	p = ch == '-'? ch = getchar(), -1 : 1;
	while (isdigit(ch))
		res = (res << 3) + (res << 1) + (ch ^ 48), ch = getchar();
	return res * p;
}

void addedge(edge *arc[], int u, int v, int w)
{
	*pt = (edge){v, w, arc[u]};
	arc[u] = pt++;
}

void gettr(int x)
{
	vis[x] = true;
	for (edge *e = arc1[x]; e; e = e->nxt)
		if (!vis[e->to])
		{
			addedge(arc2, x, e->to, e->w);
			gettr(e->to);
		}
}

void dfs(int x)
{
	for (edge *e = arc2[x]; e; e = e->nxt)
	{
		if (e->w != ans[x])
			ans[e->to] = e->w;
		else
			ans[e->to] = e->w - 1? e->w - 1 : e->w + 1;
		dfs(e->to);
	}
}

int main()
{
	n = getint(); m = getint();
	fo(i, 1, m)
	{
		int u, v, w;
		u = getint(); v = getint(); w = getint();
		addedge(arc1, u, v, w);
		addedge(arc1, v, u, w);
	}
	gettr(1);
	ans[1] = 1;
	dfs(1);
	fo(i, 1, n) printf("%d\n", ans[i]);
	return 0;
}
#include<iostream>
#include<sstream>
#include<iomanip>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<map>
#include<cmath>
#include<string>
#include<numeric>


#define rep(i,p) for(long long int i=0;i<p;i++)
#define reep(i,p) for(long long int i=1;i<=p;i++)
#define ll long long
#define mod 1000000007

using namespace std;

ll int kfj=0;
long long int sech(vector<ll int>& A,vector<vector<ll int> >& root,vector<bool>& bo,ll int n, ll int min, ll int sa){
	ll int ans;
	ll int kari;
        ans=A[n]-min;
	if(ans<sa){
	      ans=sa;
	}
	if(min>A[n]){
		min=A[n];
	}
	for(ll int i:root[n]){
		kari=sech(A,root,bo,i-1,min,ans);
		bo[i-1]=true;
		ans=std::max(kari,ans);

	}
	return ans;
}
		
	



int main(){

 ll int N,M;
 cin >> N >> M;
 vector<vector<ll int> > root(N);
 vector<ll int> A(N);
 rep(i,N){
	 cin >> A[i];
 }
 ll int X,Y;
 rep(i,M){
	 cin >> X >> Y;
	 root[X-1].push_back(Y);
 }
vector <ll int> dp(N,100000000000000);
for(ll int i=0;i<N;i++){
	for(ll int j:root[i]){
		dp[j-1]=min({A[i],dp[i],dp[j-1]});
	}
}


ll int ans=-1000000000000000;
rep(i,N){
	ans=max(ans,A[i]-dp[i]);
//	cout << dp[i] << " " ;
}





 cout << ans;















	return 0;

}

