#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
#include <random>
//#include "util.k"

using namespace std;

//呪文
#define DUMPOUT cout
#define dump(...) DUMPOUT<<"  ";DUMPOUT<<#__VA_ARGS__<<" :["<<__LINE__<<":"<<__FUNCTION__<<"]"<<endl;DUMPOUT<<"    ";dump_func(__VA_ARGS__)

typedef unsigned uint; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<double, double> pdd; typedef pair<string, string> pss;
template <typename _KTy, typename _Ty> ostream& operator << (ostream& ostr, const pair<_KTy, _Ty>& m) { ostr << "{" << m.first << ", " << m.second << "}"; return ostr; }
template <typename _KTy, typename _Ty> ostream& operator << (ostream& ostr, const map<_KTy, _Ty>& m) { if (m.empty()) { ostr << "{ }"; return ostr; } ostr << "{" << *m.begin(); for (auto itr = ++m.begin(); itr != m.end(); itr++) { ostr << ", " << *itr; } ostr << "}"; return ostr; }
template <typename _Ty> ostream& operator << (ostream& ostr, const vector<_Ty>& v) { if (v.empty()) { ostr << "{ }"; return ostr; } ostr << "{" << v.front(); for (auto itr = ++v.begin(); itr != v.end(); itr++) { ostr << ", " << *itr; }	ostr << "}"; return ostr; }
template <typename _Ty> ostream& operator << (ostream& ostr, const set<_Ty>& s) { if (s.empty()) { ostr << "{ }"; return ostr; } ostr << "{" << *(s.begin()); for (auto itr = ++s.begin(); itr != s.end(); itr++) { ostr << ", " << *itr; }	ostr << "}"; return ostr; }
template <typename _Ty> ostream& operator << (ostream& ostr, const stack<_Ty>& s) { if (s.empty()) { ostr << "{ }"; return ostr; } stack<_Ty> t(s); ostr << "{" << t.top(); t.pop(); while (!t.empty()) { ostr << ", " << t.top(); t.pop(); } ostr << "}";	return ostr; }
template <typename _Ty> ostream& operator << (ostream& ostr, const list<_Ty>& l) { if (l.empty()) { ostr << "{ }"; return ostr; } ostr << "{" << l.front(); for (auto itr = ++l.begin(); itr != l.end(); ++itr) { ostr << ", " << *itr; } ostr << "}"; return ostr; }
template <typename _KTy, typename _Ty> istream& operator >> (istream& istr, pair<_KTy, _Ty>& m) { istr >> m.first >> m.second; return istr; }
template <typename _Ty> istream& operator >> (istream& istr, vector<_Ty>& v) { for (size_t i = 0; i < v.size(); i++) istr >> v[i]; return istr; }
ll modpow(ll n, ll p, ll m) { ll result = 1; while (p > 0) { if (p & 1) result = (result * n) % m; p >>= 1; n = (n * n) % m; } return result; }
template <typename _Ty> _Ty ipow(_Ty x, _Ty n) { _Ty ret = _Ty(1); for (_Ty i = _Ty(0); i < n; i++) ret *= x; return ret; }
template<typename A, size_t N, typename T> inline void Fill(A(&array)[N], const T &val) { std::fill((T*)array, (T*)(array + N), val); }

void dump_func() { DUMPOUT << endl; }
template <class Head, class... Tail> void dump_func(Head&& head, Tail&&... tail) { DUMPOUT << head; if (sizeof...(Tail) == 0) { DUMPOUT << " "; } else { DUMPOUT << ", "; } dump_func(std::move(tail)...); }

#define PI 3.14159265358979323846
#define EPS 1e-11
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define fake false



class DisjointSet {
private:
	vector<unsigned> par;
	vector<unsigned> rank;
	vector<unsigned> sz;	// 要素の個数
	size_t set_sz;			// 集合の個数

public:

	DisjointSet() : set_sz(0) { }

	DisjointSet(size_t n) :
		par(n), rank(n, 0), sz(n, 1), set_sz(n) {
		for (size_t i = 0; i < n; i++) par[i] = i;
	}

	size_t set_size() { return set_sz; }
	size_t size(size_t v) { return sz[find(v)]; }

	void makeset() {
		par.push_back(par.size());
		rank.push_back(0);
		sz.push_back(1);
		set_sz++;
	}
	void makeset(size_t n) {
		for (size_t i = 0; i < n; i++) makeset();
	}

	size_t find(size_t x) {
		if (par[x] == x)
			return x;
		else
			return par[x] = find(par[x]);
	}

	void unite(size_t x, size_t y) {
		x = find(x);
		y = find(y);
		if (x == y) return;

		if (rank[x] < rank[y])
			par[x] = y;
		else {
			par[y] = x;
			if (rank[x] == rank[y]) rank[x]++;
		}
		sz[x] += sz[y];
		sz[y] = sz[x];
		set_sz--;
	}

	bool same(size_t x, size_t y) {
		return find(x) == find(y);
	}

	friend ostream& operator<<(ostream& ostr, const DisjointSet& ds) {
		ostr << endl << "parent : " << ds.par << endl << "rank : " << ds.rank << endl << "size : " << ds.sz << endl << "size of set : " << ds.set_sz << endl;
		return ostr;
	}
};

int main()
{
	//clock_t start, end;
	//start = clock();

	//cin.tie(0);
	//ios::sync_with_stdio(false);

	int N, M;
	cin >> N >> M;

	vector<ll> a(N);
	cin >> a;

	DisjointSet ds(N);

	REP(i, M) {
		int x, y;
		cin >> x >> y;

		ds.unite(x, y);
	}

	typedef priority_queue<ll, vector<ll>, greater<ll>> PQ;

	map<int, PQ> mp;
	REP(i, N) mp[ds.find(i)].push(a[i]);

	auto comp = [](PQ& a, PQ& b) {
		if (a.size() == 0 || b.size() == 0) return a.size() < b.size();
		if (a.size() == 1 || b.size() == 1) {
			if (a.size() == 1 && b.size() == 1) return a.top() > b.top();
			else return a.size() < b.size();
		}
		else {
			ll a1, a2, b1, b2;
			a1 = a.top(); a.pop();
			a2 = a.top();
			b1 = b.top(); b.pop();
			b2 = b.top();
			a.push(a1); b.push(b1);
			return a2 > b2;
		}
	};

	priority_queue<PQ, vector<PQ>, decltype(comp)> pq(comp);

	for (const auto& e : mp) pq.push(e.second);

	ll ans = 0;
	while (pq.size() != 1) {
		PQ v1 = pq.top(); pq.pop();
		PQ v2 = pq.top(); pq.pop();
		if (v1.empty() || v2.empty()) {
			cout << "Impossible" << endl;
			return 0;
		}

		ans += v1.top() + v2.top(); v1.pop(); v2.pop();

		if (v1.size() >= v2.size()) {
			while (!v2.empty()) {
				v1.push(v2.top()); v2.pop();
			}
			pq.push(v1);
		}
		else {
			while (!v1.empty()) {
				v2.push(v1.top()); v1.pop();
			}
			pq.push(v2);
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 21236