#include<bits/stdc++.h>
using namespace std;
long long nadjiIndeks(long long x, long long a[], int n, bool isk[])
{
    for(int i=0;i<n;i++)
        if(isk[i]==false && x==a[i]) return i;
}
void insertionSort(long long *a, int n)
{
   long long k;
   int j;
   for(int i=1;i<n;i++)
   {
      k=a[i];
      j=i;
      while(j>0 && abs(a[j-1])>abs(k))
      {
         a[j]=a[j-1];
         j--;
      }
      a[j]=k;
   }
}
int main()
{
    int n,m,sreca=0;
    cin>>n>>m;
    long long d[n];
    long long cd[n];
    bool isk[n]={false};
    for(int i=0;i<n;i++)
    {
        cin>>d[i];
        cd[i]=d[i];
    }
    insertionSort(cd,n);
    int p[m*2];
    for(int i=0;i<2*m;i+=2)
        cin>>p[i]>>p[i+1];
    int odnosi[n]={0};
    int znakInd[n];
    for(int i=0;i<n;i++)
        if(d[i]<0)
            znakInd[i]=-1;
        else
            znakInd[i]=1;
    for(int i=0;i<n;i++)
    {
        int ind=nadjiIndeks(cd[i],d,n,isk);
        isk[ind]=true;
        for(int j=0;j<2*m;j++)
        {
            if(p[j]==ind+1)
                if(j%2==0)
                {
                    if(isk[p[j+1]-1])
                    {
                        odnosi[p[j]-1]+=(znakInd[p[j]-1]-znakInd[p[j+1]-1]);
                        odnosi[p[j+1]-1]+=(znakInd[p[j]-1]-znakInd[p[j+1]-1]);
                    }
                    else
                    {
                        odnosi[p[j]-1]+=znakInd[p[j]-1];
                        odnosi[p[j+1]-1]+=znakInd[p[j]-1];
                    }
                }
                else
                {
                    if(isk[p[j-1]-1])
                    {
                        odnosi[p[j]-1]+=(znakInd[p[j]-1]-znakInd[p[j-1]-1]);
                        odnosi[p[j-1]-1]+=(znakInd[p[j]-1]-znakInd[p[j-1]-1]);
                    }
                    else
                    {
                        odnosi[p[j]-1]+=znakInd[p[j]-1];
                        odnosi[p[j-1]-1]+=znakInd[p[j]-1];
                    }
                }
        }
    }
    for(int i=0;i<n;i++)
    {
        sreca+=(d[i]*odnosi[i]);
    }
    cout<<sreca;
    return 0;
}