#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) for (int i = 0; i < (n); i++)

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n, m;
    cin >> n >> m;
    vector<int> ws(n);
    for (int i = 0; i < n; i++) cin >> ws[i];
    vector<vector<int>> adj(n);
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }

    vector<bool> hasi(n);
    vector<int> deg(n);
    queue<int> que;
    for (int i = 0; i < n; i++) {
        deg[i] = adj[i].size();
        if (adj[i].size() == 1) {
            hasi[i] = true;
            que.push(i);
        }
    }

    if (que.empty()) {
        cout << accumulate(ws.begin(), ws.end(), 0) << endl;
        return 0;
    }

    while (!que.empty()) {
        int v = que.front();
        que.pop();
        for (int a : adj[v]) {
            if (hasi[a]) continue;
            deg[a]--;
            if (deg[a] == 1) {
                hasi[a] = true;
                que.push(a);
            }
        }
    }

    vector<int> girigiri;
    for (int i = 0; i < n; i++) {
        if (!hasi[i]) continue;
        bool ok = false;
        for (int a : adj[i]) {
            if (!hasi[a]) ok = true;
        }
        if (ok) {
            girigiri.push_back(i);
        }
    }

    if (girigiri.empty()) {
        // tree
        int ans = 0;
        function<void(int, int, int)> dfs = [&](int v, int p, int acc) {
            ans = max(ans, acc);
            for (int s : adj[v]) {
                if (s != p) {
                    dfs(s, v, acc + ws[s]);
                }
            }
        };
        dfs(0, -1, ws[0]);
        cout << ans << endl;
        return 0;
    }

    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (!hasi[i]) {
            ans += ws[i];
        }
    }

    int N = girigiri.size();
    vector<int> score(N);
    auto get_max = [&](int u) {
        int nax = 0;
        function<void(int, int, int)> dfs = [&](int v, int p, int acc) {
            nax = max(nax, acc);
            for (int s : adj[v]) {
                if (s != p && hasi[s]) {
                    dfs(s, v, acc + ws[s]);
                }
            }
        };
        dfs(u, -1, ws[u]);
        return nax;
    };
    for (int i = 0; i < N; i++) {
        score[i] = get_max(girigiri[i]);
    }

    if (hasi[0]) {
        bool nyan = false;
        for (int i = 0; i < N; i++) {
            if (girigiri[i] == 0) {
                ans += ws[0];
                score[i] -= ws[0];
                nyan = true;
                break;
            }
        }
        if (nyan) {
            ans += *max_element(score.begin(), score.end());
            cout << ans << endl;
            return 0;
        }
        int giri = -1;
        int iki = 0;
        function<void(int, int, int)> dfs = [&](int v, int p, int acc) {
            bool hoge = false;
            for (int s : adj[v]) {
                if (s != p) {
                    if (!hasi[s]) {
                        giri = v;
                        iki = acc;
                        return;
                    }
                    hoge = true;
                    dfs(s, v, acc + ws[s]);
                }
            }
        };
        dfs(0, -1, ws[0]);
        ans += iki;
        assert(giri != -1);
        vector<bool> used(n);
        function<void(int, int)> kek = [&](int v, int p) {
            if (v == 0) {
                used[v] = true;
                return;
            }
            for (int s : adj[v]) {
                if (s != p && hasi[s]) {
                    kek(s, v);
                    if (used[s]) {
                        used[v] = true;
                        return;
                    }
                }
            }
        };
        kek(giri, -1);
        assert(used[0]);
        int nax = 0;
        function<void(int, int, int)> genkai = [&](int v, int p, int acc) {
            nax = max(nax, acc);
            for (int s : adj[v]) {
                if (s != p && hasi[s]) {
                    int po = acc;
                    if (!used[s]) {
                        po += ws[s];
                    }
                    genkai(s, v, po);
                }
            }
        };
        genkai(giri, -1, 0);
        for (int i = 0; i < N; i++) {
            if (girigiri[i] == giri) {
                score[i] = nax;
                break;
            }
        }
        ans += *max_element(score.begin(), score.end());
        cout << ans << endl;
    } else {
        ans += *max_element(score.begin(), score.end());
        cout << ans << endl;
    }
}



Measured memory_bytes: 19072