#include <bits/stdc++.h>
#define K int(1e5 + 10)
#define INF ll(1e18)
#define MOD (long long)(1e9 + 7)
#define endl "\n"
using namespace std;
typedef unsigned int ui;
typedef long long ll;
typedef unsigned long long ull;

vector<vector<int>> g;
vector<ll> d, ts;
bool vis[K] = {};

void topsort(int a){
    if (vis[a]) return;
    vis[a] = 1;
    for (int i : g[a])
        topsort(i);
    ts.push_back(a);
}

void solve(){
    int n, m;
    cin >> n >> m;
    d.resize(n); 
    g.resize(n);
    for (ll &i : d) cin >> i;
    int a, b;
    while (m--){
        cin >> a >> b;
        --a, --b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    for (int i = 0; i < n; i++)
        topsort(i);
    vector<ll> dp(n, 0);
    for (int i = 0; i < K; i++) vis[i] = 0;
    for (int i = n - 1; i >= 0; i--){
        vis[i] = 1;
        for (int j : g[ts[i]]){
            if (vis[j]) continue;
            vis[j] = 1;
            if (dp[i] + dp[j] < dp[i] + dp[j] - d[i] - d[j]){
                dp[i] -= d[i];
                dp[j] -= d[j];
            }
            else if (dp[i] + dp[j] < dp[i] + dp[j] + d[i] + d[j]){
                dp[i] += d[i];
                dp[j] += d[j];
            }
        }
    }
    ll ans = 0;
    for (ll i : dp)
        ans += i;
    cout << ans << endl;
}
 
int main(){
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
 
    int t = 1;
    //cin >> t;
    while (t--)
        solve();
 
    return 0;
}