#include <bits/stdc++.h>

using namespace std;

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cout << setprecision(10) << fixed;

	long long n, m;
	cin >> n >> m;
	vector<long long> a(n);
	vector<vector<long long>> g(n);
	for (long long i = 0; i < n; ++i)
		cin >> a[i];

	for (long long i = 0; i < m; ++i)
	{
		long long x, y;
		cin >> x >> y;
		--x, --y;
		g[x].emplace_back(y);
	}
	vector<pair<long long, long long>> p(n, make_pair(-1e15, 1e15));
	long long ans = -1e15;
	for (long long i = 0; i < n; ++i)
	{
		p[i].second = min(a[i], p[i].second);
		for (long long u : g[i])
		{
			ans = max(ans, a[u] - p[i].second);
			p[u].second = min(p[u].second, p[i].second);
			// p[u].first = max(a[u], p[i].first);
			// p[i].second =
		}
	}
	cout << ans << '\n';
}
#include <bits/stdc++.h>
using namespace std;

#define forn(i,m,n) for(int i=m;i<n;i++)
#define vv vector
#define vi vv<int>
#define ii pair<int,int>
#define vii vv<ii>
#define mp make_pair
#define pb push_back
#define PI 3.141592653589
#define ll long long
#define pll pair<ll,ll>
#define vl vv<ll>
#define ff first
#define ss second
#define MOD 1000000007


bool is_prime[1000001];
vi prime;
void sieve(int n)
{
    memset(is_prime,true,sizeof(is_prime));
    for(int i=2;i*i<=n;i++)
    {
        if(is_prime[i])
        {
            for(int j=i*i;j<=n;j+=i)
            {
                is_prime[j]=false;
            }
        }
    }
    forn(i,2,n+1)
    {
        if(is_prime[i])
            prime.pb(i);
    }
}

ll ex(ll a,ll b)
{
    ll res=1;
    a=a%MOD;
    while(b)
    {
        if(b%2){res=(res*a)%MOD;b--;}
        b/=2;
        a=(a*a)%MOD;
    }
    return res;
}

ll fermat_inv(ll a){ return ex(a,MOD-2); }
ll max(ll a,ll b){ return a>b?a:b; }
ll min(ll a,ll b){ return a<b?a:b; }

int gcd(int a,int b) { return (a%b==0)?b:gcd(b,a%b); }

ll fact[200005];
ll finv[200005];
void factorial(int n){
    fact[0]=1;
    finv[0]=1;
    for(ll i=1;i<=n;i++)
        fact[i]=fact[i-1]*i,fact[i]%=MOD,finv[i]=fermat_inv(fact[i]);
}
ll ncr(ll n,ll r)
{
    if(n<r)
        return -1;
    else{
        ll x=finv[r]*finv[n-r]%MOD;
        return fact[n]*x%MOD;
    }
}

vv<vi> adj(200005);
vi mn(200005,INT_MAX);
vi val(200005);
int ans;

void dfs(int v)
{
    mn[v]=min(mn[v],val[v]);
    for(int x:adj[v])
    {
        ans=max(ans,val[x]-mn[v]);
        mn[x]=min(mn[x],mn[v]);
    }
    //cout<<"mn["<<v<<"]: "<<mn[v]<<"\n";    
}


int main()
{
    ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        #ifndef ONLINE_JUDGE
            freopen("input.txt", "r", stdin);
            freopen("output.txt", "w", stdout);
        #endif
    //sieve(1000000);
    //factorial(200005);

    int te=1;
    //cin>>te;
    while(te--)
    {
        ll n,m,a,b;
        cin>>n>>m;
        //cout<<n<<m<<"\n";
        forn(i,1,n+1)
            cin>>val[i];
        //int st=INT_MAX;
        forn(i,0,m)
        {
            cin>>a>>b;
            if(a>b)
                swap(a,b);
            //cout<<a<<b;
            adj[a].pb(b);
            //adj[b].pb(a);
        }
        
        ans=INT_MIN;
        forn(i,1,n+1)
            dfs(i);
        cout<<ans;               
    }
}
