#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

template <typename _Ty> ostream& operator << (ostream& ostr, const priority_queue<_Ty, vector<_Ty>, greater<_Ty>>& pq) {
	priority_queue<_Ty, vector<_Ty>, greater<_Ty>> pqtmp(pq);
	
	if (pqtmp.empty()) { ostr << "{ }"; return ostr; } 
	
	ostr << "{" << pqtmp.top(); pqtmp.pop();
	while (!pqtmp.empty()) {
		ostr << ", " << pqtmp.top(); pqtmp.pop();
	}
	ostr << "}";
	return ostr; 
}


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;
	for (int i = N - 1; i >= 0; i--) mp[ds.find(i)].push(a[i]);

	auto comp = [](PQ& a, PQ& b) {
		if (a.size() == 1 || b.size() == 1) {
			if (a.size() == 0 || b.size() == 0) return a.size() > b.size();
			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);
	
	//priority_queue<PQ, vector<PQ>, decltype(comp)> pq2(pq);
	
	//while (!pq2.empty()) {
	//	cout << pq2.top() << endl;
	//	pq2.pop();
	//}

	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;
		}

	//	dump(v1, v2);

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

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

		//dump(v1, v2, v3);
	}

	cout << ans << endl;

	return 0;
}




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);
	}

	map<int, vector<ll>> mp;
	for (int i = N - 1; i >= 0; i--) mp[ds.find(i)].push_back(a[i]);

	for (auto& e : mp) sort(all(e.second), greater<ll>());

	auto comp = [](vector<ll>& a, vector<ll>& b) {
		if (a.size() == 1 || b.size() == 1) {
			if (a.size() == 1 && b.size() == 1) return a[0] < b[0];
			else return a.size() < b.size();
		}
		else {
			return a[a.size() - 2] > b[b.size() - 2];
		}
	};

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

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

	ll ans = 0;
	while (pq.size() != 1) {
		vector<ll> v1 = pq.top(); pq.pop();
		vector<ll> v2 = pq.top(); pq.pop();

		vector<ll> v3;
		ans += v1.back() + v2.back(); v1.pop_back(); v2.pop_back();

		if (v1.size() + v2.size() == 0) {
			cout << "Impossible" << endl;
			return 0;
		}

		int pos1 = 0, pos2 = 0;
		while (pos1 != v1.size() || pos2 != v2.size()) {
			if (pos1 == v1.size()) {
				v3.push_back(v2[pos2]); pos2++;
			}
			else if (pos2 == v2.size()) {
				v3.push_back(v1[pos1]); pos1++;
			}
			else {
				if (v1[pos1] >= v2[pos2]) {
					v3.push_back(v1[pos1]); pos1++;
				}
				else {
					v3.push_back(v2[pos2]); pos2++;
				}
			}
		}


		pq.push(v3);
		//dump(v1, v2, v3);
	}
	
	cout << ans << endl;
	
	return 0;
}



Measured memory_bytes: 21236