#include <bits/stdc++.h>
#define ll    long long
#define pb    push_back
#define ld    long double
#define sz    size()
#define lala  for(ll i=0;i<n;i++)
#define pll   pair<ll,ll>
#define ed    "\n"
#define ct    cout
#define m_p   make_pair
#define vi    vector<ll>
#define vc    vector<char>
#define ff    first
#define ss    second

using namespace std;

void bahut_tezz()
{
    std::ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}


void jai_bajrangbali()
{
    ll k,n,m,x,y,cnt=0,res=0,mx=1;
    ll sum=0;
    bool ash=false;
    string s;
    cin>>n;
    ll a[n];
    lala
    {
        cin>>a[i];
    }

    sort(a,a+n);

//    x=upper_bound(a,a+n,a[n-2])-a+1-1;
//    ct<<x<<ed;

    for(ll i=0;i<n-1;i++)
    {
        x=upper_bound(a,a+n,a[i])-a;
        cnt=cnt+abs(n-x);
    }

    ct<<cnt<<ed;


}

int main()
{
    bahut_tezz();
    long long t=1;
    //cin>>t;
    while(t--)jai_bajrangbali();

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl '\n'
//#define int long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define BIT(n) (1LL << (n))
#define TOUPPER(s) transform(s.begin(), s.end(), s.begin(), ::toupper)
#define TOLOWER(s) transform(s.begin(), s.end(), s.begin(), ::tolower)
#define FILLZERO(s, n)                      \
    do {                                    \
        ostringstream os;                   \
        os << setw(n) << setfill('0') << s; \
        s = os.str();                       \
    } while (0);
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())  // sortしてからつかうこと

using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using pi = pair<int, int>;
template <typename T>
using Pq = priority_queue<T>;
template <typename T>
using pQ = priority_queue<T, vector<T>, greater<T>>;

template <typename T>
vector<T> make_vec(size_t a, T n) {
    return vector<T>(a, n);
}
template <typename T, typename... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <class T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
bool isProductOverflow(T a, T b) {
    return (a > numeric_limits<T>::max() / b);
}
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec) is >> x;
    return is;
}

__attribute__((constructor)) void ioInit() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    cout << std::fixed << std::setprecision(10);
}

constexpr ll MOD = 1e9 + 7;
// constexpr ll MOD = 998244353;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

long long ceilSqrt(long long n) {
    ll res = sqrt(n) - 1;
    while ((res + 1) * (res + 1) <= n) res++;
    return res;
}

signed main() {
    cin >> N >> M;
    vi a(N);
    cin >> a;
    vvi adj(N);
    REP(i, M) {
        cin >> X >> Y;
        X--, Y--;
        adj[X].push_back(Y);
    }
    vi b(N, INF);
    b[0] = INF;
    REP(i, N) {
        for (auto j : adj[i]) {
            chmin(b[j], min(a[i], b[i]));
        }
    }
    ans = -INF;
    REP(i, N) { chmax(ans, (ll)a[i] - b[i]); }
    cout << ans << endl;
}