/*** keep hungry and calm PushyTao!***/
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <math.h>

using namespace std;
typedef long long ll;
#define HEAP(...) priority_queue<__VA_ARGS__ >
#define heap(...) priority_queue<__VA_ARGS__,vector<__VA_ARGS__ >,greater<__VA_ARGS__ > >
template<class T> inline T min(T& x, const T& y) { return x > y ? y : x; }
template<class T> inline T max(T& x, const T& y) { return x < y ? y : x; }
ll read() {
	ll c = getchar(), Nig = 1, x = 0; while (!isdigit(c) && c != '-')c = getchar();
	if (c == '-')Nig = -1, c = getchar();
	while (isdigit(c))x = ((x << 1) + (x << 3)) + (c ^ '0'), c = getchar();
	return Nig * x;
}
#define read read()
const ll inf = 1e15;
const ll INF = 0x3f3f3f3f;
const int maxn = 1e6 + 7;
const int mod = 1000000007;
#define PI acos(-1.0)
typedef int itn;
namespace usual{
    inline ll gcd(ll a, ll b)
    {
        ll t;
        while (b != 0)
        {
            t = a % b; a = b; b = t;
        }
        return a;
    }
    inline ll qPow(ll x, ll k)
    {
        ll res = 1;
        while (k) {
            if (k & 1) res = (res * x);
            k >>= 1;
            x = (x * x);
        }
        return res;
    }
    inline ll oula(ll x) {
        ll res = x;
        for (ll i = 2; i <= x / i; i++) {
            if (x % i == 0) {
                res = res / i * (i - 1);
                while (x % i == 0) x /= i;
            }
        }
        if (x > 1) res = res / x * (x - 1);
        return res;
    }
}
using namespace usual;
priority_queue <int, vector<int>, greater<int> > xiaogen;
priority_queue <int, vector<int>, less<int> > dagen;
itn a[maxn],b[maxn];
ll cnt[maxn];
int main() {
    int n = read;
    for(int i=1;i<=n;i++){
        a[i] = read;
        cnt[a[i]+200] ++;
    }
    ll ans = 0;
    for(ll i=0;i<=400;i++){
        for(ll j=i+1;j<=400;j++){
            ans += cnt[i] * cnt[j] * (i-j) * (i-j);
        }
    }
    cout<<ans<<endl;
	return 0;
}/// ac_code

/**

**/

#include <bits/stdc++.h>
// #include <atcoder/all>
#define rep(i, a) for (int i = (int)0; i < (int)a; ++i)
#define rrep(i, a) for (int i = (int)a - 1; i >= 0; --i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define RREP(i, a, b) for (int i = (int)a - 1; i >= b; --i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define popcount __builtin_popcount
using ll = long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

// #pragma GCC target("avx2")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
template <class T>
inline bool chmin(T &a, T b)
{
	if (a > b)
	{
		a = b;
		return true;
	}
	return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
	if (a < b)
	{
		a = b;
		return true;
	}
	return false;
}

template <typename T>
T mypow(T x, T n, const T &p = -1)
{ //x^nをmodで割った余り
	T ret = 1;
	while (n > 0)
	{
		if (n & 1)
		{
			if (p != -1)
				ret = (ret * x) % p;
			else
				ret *= x;
		}
		if (p != -1)
			x = (x * x) % p;
		else
			x *= x;
		n >>= 1;
	}
	return ret;
}

using namespace std;
// using namespace atcoder;

void solve()
{
	int n,m;
	cin>>n>>m;
	vector<ll>a(n);
	rep(i,n)cin>>a[i];
	vector<vector<int>>g(n);
	rep(i,m){
		int x,y;
		cin>>x>>y;
		x--;y--;
		g[x].eb(y);
	}
	vector<ll>dp(n,INF);
	ll ans=-INF;
	vector<bool>visited(n);
	auto dfs=[&](auto self,int v)->void{
		visited[v]=true;
		for(auto x:g[v]){
			chmin(dp[x],min(a[v],dp[v]));
		}
	};
	rep(i,n){
		dfs(dfs,i);
	}
	rep(i,n){
		chmax(ans,a[i]-dp[i]);
	}
	cout<<ans;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}
