#include <iostream>
#include <string>
using namespace std;

int N,t;
string s;

int main()
{
	cin >> N >> t;
	cin >> s;
	bool roundup = 0;
	int cut = s.size();
	int i;
	for(i=0;s[i]!='.';i++)
		;
	for(i++;s[i]<'5';i++)
		;
	for(;s[i]!='.';i--)
	{
		if(roundup)
		{
			if(s[i]=='9') s[i] = '0';
			else
			{
				s[i] = (char)(s[i]+1);
				roundup = 0;
			}
		}
		if(s[i] >= '5' && t)
		{
			cut = i;
			roundup = 1;
			t--;
		}
	}
	for(i--;i>=0;i--)
	{
		if(roundup)
		{
			if(s[i]=='9') s[i] = '0';
			else
			{
				s[i] = (char)(s[i]+1);
				roundup = 0;
			}
		}
	}
	if(roundup) cout << 1;
	for(;s[cut-1]=='0';cut--)
		;
	if(s[cut-1]=='.') cut--;
	for(i=0;i<cut;i++)
		cout << s[i];
	cout << '\n';
}


#include <iostream>
#include <string>
using namespace std;

int N,t;
string s;

int main()
{
	cin >> N >> t;
	cin >> s;
	bool roundup = 0;
	int cut = s.size();
	int i;
	for(i=0;s[i]!='.';i++)
		;
	for(i++;i<s.size() && s[i]<'5';i++)
		;
	if(i==s.size()) i--;
	for(;s[i]!='.';i--)
	{
		if(roundup)
		{
			if(s[i]=='9') s[i] = '0';
			else
			{
				s[i] = (char)(s[i]+1);
				roundup = 0;
			}
		}
		if(s[i] >= '5' && t)
		{
			cut = i;
			roundup = 1;
			t--;
		}
	}
	for(i--;i>=0;i--)
	{
		if(roundup)
		{
			if(s[i]=='9') s[i] = '0';
			else
			{
				s[i] = (char)(s[i]+1);
				roundup = 0;
			}
		}
	}
	if(roundup) cout << 1;
	for(;s[cut-1]=='0';cut--)
		;
	if(s[cut-1]=='.') cut--;
	for(i=0;i<cut;i++)
		cout << s[i];
	cout << '\n';
}


#include<bits/stdc++.h>

using namespace std;

int main()
{
	int n,k;
	char score[300000];
	cin >> n >> k;
	scanf("%s", score);
	int last_4 = 0;
	int decimal_point_pos;
	for(int i=0;i<n;i++)
	{
		if(score[i] == '.')
		{
			decimal_point_pos = i;
			break;
		}
	}
		for(int i=decimal_point_pos + 1; i<n;i++)
		{
			if(score[i] >= '5')
			{
				if(last_4)
				{
					int op = min(k, i-last_4+1);
					if(i - op == decimal_point_pos)
					{
						score[i - op - 1]++;
						score[i - op] = 0;
						n = i - op;
						break;
					}
					else
					{
						score[i - op]++;
						score[i - op + 1] = 0;
						n = i - op + 1;
					}
				}
				else
				{
					int j=i-1;
					if(score[j] == '.')
					{
						score[j-1]++;
						score[j] = 0;
						n = j;
						break;
					}
					else
					{
						score[j]++;
						score[j+1] = 0;
						n = j+1;
						break;
					}
				}
			}
			else if(score[i] == '4')
			{
				if(last_4)
					;
				else
					last_4 = i;
			}
			else
				last_4 = 0;
		}
	for(int i=0;i<n;i++)
		printf("%c",score[i]);
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

int main()
{
	int n,k;
	char score[300000];
	bool flag = false;
	cin >> n >> k;
	scanf("%s", score);
	int last_4 = 0;
	int decimal_point_pos;
	for(int i=0;i<n;i++)
	{
		if(score[i] == '.')
		{
			decimal_point_pos = i;
			break;
		}
	}
		for(int i=decimal_point_pos + 1; i<n;i++)
		{
			if(score[i] >= '5')
			{
				if(last_4)
				{
					int op = min(k, i-last_4+1);
					if(i - op == decimal_point_pos)
					{
						score[i - op - 1]++;
						score[i - op] = 0;
						n = i - op;
						for(int k=decimal_point_pos-1; score[k] == '0'+ 10 && k >= 0; k--)
						{
							if(k == 0)
							{
								score[k] = '0';
								flag = true;
							}
							else
							{
								score[k] = '0';
								score[k-1]++;
							}
						}
						break;
					}
					else
					{
						score[i - op]++;
						score[i - op + 1] = 0;
						n = i - op + 1;
					}
				}
				else
				{
					int j=i-1;
					if(score[j] == '.')
					{
						score[j-1]++;
						score[j] = 0;
						n = j;
						for(int k=j-1; score[k] == '0'+ 10 && k >= 0; k--)
						{
							if(k == 0)
							{
								score[k] = '0';
								flag = true;
							}
							else
							{
								score[k] = '0';
								score[k-1]++;
							}
						}
						break;
					}
					else
					{
						score[j]++;
						score[j+1] = 0;
						n = j+1;
						break;
					}
				}
			}
			else if(score[i] == '4')
			{
				if(last_4)
					;
				else
					last_4 = i;
			}
			else
				last_4 = 0;
		}
	if(flag)
		cout << "1";
	for(int i=0;i<n;i++)
		printf("%c",score[i]);
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

int main()
{
	int n,k;
	char score[300000];
	bool flag = false;
	cin >> n >> k;
	scanf("%s", score);
	int last_4 = 0;
	int decimal_point_pos;
	for(int i=0;i<n;i++)
	{
		if(score[i] == '.')
		{
			decimal_point_pos = i;
			break;
		}
	}
		for(int i=decimal_point_pos + 1; i<n;i++)
		{
			if(score[i] >= '5')
			{
				if(last_4)
				{
					int op = min(k, i-last_4+1);
					if(i - op == decimal_point_pos)
					{
						score[i - op - 1]++;
						score[i - op] = 0;
						n = i - op;
						break;
					}
					else
					{
						score[i - op]++;
						score[i - op + 1] = 0;
						n = i - op + 1;
					}
				}
				else
				{
					int j=i-1;
					if(score[j] == '.')
					{
						score[j-1]++;
						score[j] = 0;
						n = j;
						for(int k=j-1; score[k] == '0'+ 10 && k >= 0; k--)
						{
							if(k == 0)
							{
								score[k] = '0';
								flag = true;
							}
							else
							{
								score[k] = '0';
								score[k-1]++;
							}
						}
						break;
					}
					else
					{
						score[j]++;
						score[j+1] = 0;
						n = j+1;
						break;
					}
				}
			}
			else if(score[i] == '4')
			{
				if(last_4)
					;
				else
					last_4 = i;
			}
			else
				last_4 = 0;
		}
	if(flag)
		cout << "1";
	for(int i=0;i<n;i++)
		printf("%c",score[i]);
	return 0;
}


#include<iostream>
using namespace std;
#include<set>
#include<map>
map<long long,long long>mp;
set<long long>s;
long long parent[100001];
long long rak[100001];
long long g[100001];
long long n;
long long find(long long i) {
    if(parent[i]==i)
        return i;
    else
        return parent[i]=find(parent[i]);
}
void union_set(long long a,long long b) {
    long long x=find(a);
    long long y=find(b);
    if(rak[x]<rak[y])
        swap(x,y);
    parent[y]=x;
    /*if(mp[x]==0)
    mp[x]=min(g[a],g[b]);
    else */

    mp[x]=min(mp[x],mp[y]);
    mp[x]=min(mp[x],min(mp[a],mp[b]));
    if(rak[x]==rak[y])
        rak[x]++;
}

int main()
{
    int m;
    cin>>n>>m;
    for(int i=1; i<=n; i++)
        cin>>g[i];
    for(int i=1; i<=n; i++) {
        parent[i]=i;
        mp[i]=g[i];
    }
    while(m--) {
        long long l,r;
        cin>>l>>r;
        union_set(l,r);
    }
    long long ans=0;
    for(int i=1; i<=n; i++) {
        s.insert(parent[i]);
        //cout<<parent[i];
    }
    for(auto &it:s)
        ans+=mp[it];
    /*for(int i=1;i<=n;i++)
    cout<<mp[parent[i]];    */

    cout<<ans<<endl;
    return 0;
}


#include <iostream>
#include <bits/stdc++.h>
using namespace std;
const int N=1e5;
int n,m,mn=1e6;
unsigned long long sum=0,sum2=0;
bool vis[N];
vector<int> v[N];
map<int,int>mp;

void dfs(int node){
    vis[node]=1;
        mn=min(mn,mp[node]);
    for(int i:v[node]){
        mn=min(mn,mp[i]);
        if(!vis[i])
            dfs(i);
    }
}
int main()
{
    int y,z;
    cin>>n>>m;
    for (int i=1;i<=n;++i){
        cin>>y;
        mp[i]=y;
        sum2+=y;
    }
    if (m==0) {
        cout <<sum2;
        return 0;
    }
    for (int i=0;i<m;++i){
        cin>>y;
        cin>>z;
        v[y].push_back(z);
        v[z].push_back(y);
    }
    for (int i=1;i<=n;++i){
        if (!vis[i]){
            mn=1e6;
            dfs(i);
            sum+=mn;
        }
    }
    cout <<sum;

}


#include <iostream>
#include <bits/stdc++.h>
using namespace std;
const int N=1e5;
int n,m,mn=1e6;
long long sum=0,sum2=0;
bool vis[N];
vector<int> v[N];
map<int,int>mp;

void dfs(int node){
    vis[node]=1;
    mn=min(mn,mp[node]);
    for(int i:v[node])
        if(!vis[i])
            dfs(i);
}
int main()
{
    int y,z;
    mp[mn]=1e6;
    cin>>n>>m;
    for (int i=1;i<=n;++i){
        cin>>y;
        mp[i]=y;
        sum2+=y;
    }
    if (m==0) {
        cout <<sum2;
        return 0;
    }
    for (int i=0;i<m;++i){
        cin>>y;
        cin>>z;
        v[y].push_back(z);
        v[z].push_back(y);
    }
    for (int i=1;i<=n;++i){
            mn=1e6;
        if (!vis[i]){
            dfs(i);
            sum+=mn;
        }
    }
    cout <<sum;

}


#include <iostream>
#include <bits/stdc++.h>
using namespace std;
const int N=1e5;
int n,m;
long long sum=0;
bool vis[N];
vector <int> b;
vector<int> v[N];
map<int,int>mp;
void dfs(int node){
    vis[node]=1;
    for(int i:v[node])
        if(!vis[i]){
            sum-=mp[i];
            dfs(i);
        }
}
int main()
{
    int y,z,mn=1e6;
    mp[mn]=1e6;
    cin>>n>>m;
    for (int i=1;i<=n;++i){
        cin>>y;
        mp[i]=y;
        sum+=y;
    }
    if (m==0) {
        cout <<sum;
        return 0;
    }
    for (int i=0;i<m;++i){
        cin>>y;
        cin>>z;
        mn=(mp[z]>=mp[y])?((mp[y]>=mp[mn])?mn:y):((mp[z]>=mp[mn])?mn:z);
        v[y].push_back(z);
        v[z].push_back(y);
        (mp[z]>=mp[y])?b.push_back(y):b.push_back(z);
    }
    dfs(mn);
    for (int i=0;i<b.size();++i){
        dfs(b[i]);
    }
    cout <<sum;

}


#include <iostream>
#include <bits/stdc++.h>
using namespace std;
const int N=1e5;
int n,m;
long long sum=0;
bool vis[N];
vector <int> b;
vector<int> v[N];
map<int,int>mp;
void dfs(int node){
    vis[node]=1;
    for(int i:v[node])
        if(!vis[i]){
            sum-=mp[i];
            cout<<mp[i]<<"   " <<sum<<"   ";
            dfs(i);
        }
}
int main()
{
    int y,z,mn=1e6;
    mp[mn]=1e6;
    cin>>n>>m;
    for (int i=1;i<=n;++i){
        cin>>y;
        mp[i]=y;
        sum+=y;
    }
    if (m==0) {
        cout<<sum;
        return 0;
    }
    for (int i=0;i<m;++i){
        cin>>y;
        cin>>z;
        mn=(mp[z]>=mp[y])?((mp[y]>=mp[mn])?mn:y):((mp[z]>=mp[mn])?mn:z);
        v[y].push_back(z);
        v[z].push_back(y);
        (mp[z]>=mp[y])?b.push_back(y):b.push_back(z);
    }
    cout<<mn<<endl;
    dfs(mn);
    for (int i=0;i<b.size();++i){
        dfs(b[i]);
    }
    cout <<endl<<sum;

}


#include <iostream>
#include <bits/stdc++.h>
using namespace std;
const int N=1e5;
int n,m;
long long sum=0,sum2=0,mn=1e10;
bool vis[N];
vector<int> v[N];
map<int,int>mp;

void dfs(int node){
    vis[node]=1;
    if(mn>=mp[node])
        mn=mp[node];
    for(int i:v[node])
        if(!vis[i])
            dfs(i);

}
int main()
{
    int y,z;
    cin>>n>>m;
    for (int i=1;i<=n;++i){
        cin>>y;
        mp[i]=y;
        sum2+=y;
    }
    if (m==0) {
        cout <<sum2;
        return 0;
    }
    for (int i=0;i<m;++i){
        cin>>y;
        cin>>z;
        v[y].push_back(z);
        v[z].push_back(y);
    }
    for (int i=1;i<=n;++i){
        if (!vis[i]){
            mn=1e10;
            dfs(i);
            sum+=mn;
        }
    }
    cout <<sum;
}


#include <iostream>
#include <bits/stdc++.h>
using namespace std;
const int N=1e5+1;
int n,m;
long long sum=0,sum2=0,mn=1e9;
bool vis[N];
vector<int> v[N];
map<int,long long>mp;

void dfs(int node){
    vis[node]=1;
    mn=min(mn,mp[node]);
    for(int i:v[node])
        if(!vis[i])
            dfs(i);

}
int main()
{
    int y,z;
    cin>>n>>m;
    for (int i=1;i<=n;++i){
        cin>>y;
        mp[i]=y;
        sum2+=y;
    }
    if (m==0) {
        cout <<sum2;
        return 0;
    }
    for (int i=0;i<m;++i){
        cin>>y;
        cin>>z;
        v[y].push_back(z);
        v[z].push_back(y);
    }
    for (int i=1;i<=n;++i){
        if (!vis[i]){
            mn=1e9;
            dfs(i);
            sum+=mn;
        }
    }
    cout <<sum;
}


#include <iostream>
#include <bits/stdc++.h>
using namespace std;
const int N=1e5;
int n,m;
long long sum=0,sum2=0,mn=1e10;
bool vis[N];
vector<int> v[N];
map<int,int>mp;

void dfs(int node){
    vis[node]=1;
    if(mn>mp[node])
        mn=mp[node];
    for(int i:v[node])
        if(!vis[i])
            dfs(i);

}
int main()
{
    int y,z;
    cin>>n>>m;
    for (int i=1;i<=n;++i){
        cin>>y;
        mp[i]=y;
        sum2+=y;
    }
    if (m==0) {
        cout <<sum2;
        return 0;
    }
    for (int i=0;i<m;++i){
        cin>>y;
        cin>>z;
        v[y].push_back(z);
        v[z].push_back(y);
    }
    for (int i=1;i<=n;++i){
        if (!vis[i]){
            mn=1e10;
            dfs(i);
            sum+=mn;
        }
    }
    cout <<sum;
}


#include <iostream>
#include <bits/stdc++.h>
using namespace std;
const int N=1e5;
int n,m;
long long sum=0;
bool vis[N];
vector <int> b;
vector<int> v[N];
map<int,int>mp;
void dfs(int node){
    vis[node]=1;
    for(int i:v[node])
        if(!vis[i]){
            sum-=mp[i];
            dfs(i);
        }
}
int main()
{
    int y,z,mn=1e6;
    mp[mn]=1e6;
    cin>>n>>m;
    for (int i=1;i<=n;++i){
        cin>>y;
        mp[i]=y;
        sum+=y;
    }
    if (m==0) {
        return 0;
    }
    for (int i=0;i<m;++i){
        cin>>y;
        cin>>z;
        mn=(mp[z]>=mp[y])?((mp[y]>=mp[mn])?mn:y):((mp[z]>=mp[mn])?mn:z);
        v[y].push_back(z);
        v[z].push_back(y);
        (mp[z]>=mp[y])?b.push_back(y):b.push_back(z);
    }
    dfs(mn);
    for (int i=0;i<b.size();++i){
        dfs(b[i]);
    }
    cout <<sum;

}


#include <iostream>
#include <bits/stdc++.h>
using namespace std;
const int N=1e5;
int n,m;
long long sum=0,sum2=0,mn=1e10;
bool vis[N];
vector<int> v[N];
map<int,int>mp;

void dfs(int node){
    vis[node]=1;
    mn=(mn>=mp[node])?mp[node]:mn;
    for(int i:v[node])
        if(!vis[i])
            dfs(i);

}
int main()
{
    int y,z;
    cin>>n>>m;
    for (int i=1;i<=n;++i){
        cin>>y;
        mp[i]=y;
        sum2+=y;
    }
    if (m==0) {
        cout <<sum2;
        return 0;
    }
    for (int i=0;i<m;++i){
        cin>>y;
        cin>>z;
        v[y].push_back(z);
        v[z].push_back(y);
    }
    for (int i=1;i<=n;++i){
        if (!vis[i]){
            mn=1e10;
            dfs(i);
            sum+=mn;
        }
    }
    cout <<sum;
}


#include<bits/stdc++.h>
#define pi              acos(-1)
#define ll              long long
#define ld              long double
#define gcd             __gcd
#define bitscount       __builtin_popcount
#define ff              first
#define ss              second
#define MAXX            1e18
#define MAX             *max_element
#define MIN             *min_element
#define pll             pair<ll, ll>
#define pb              push_back
#define FastRead        ios_base::sync_with_stdio(false);cin.tie(NULL)
//__builtin_popcount()  -->  counts how many 1 s are in a binary represented integer
//accumulate() --> finds sum of an array of integers
using namespace std;
ll n, m, nodes[100005], visited[100005], u, v;
int findit(ll x)
{
    return (x != visited[x]) ? visited[x] = findit(visited[x]) : x;
}
int main()
{
    FastRead;

    ll i, ans = 0;
    cin>>n>>m;

    for(i=1; i<=n; i++){
        cin>>nodes[i];
        visited[i] = i;
    }

    for(i=1; i<=m; i++){
        cin>>u>>v;

        u = findit(visited[u]);
        v = findit(visited[v]);

        if(u != v){
            visited[v] = u;
            nodes[u] = min(nodes[u], nodes[v]);
        }
    }

    for(i=1; i<=n; i++){
        if(visited[i] == i)
            ans += nodes[i];
    }

    cout<<ans;
    return 0;
}


#include<bits/stdc++.h>
#define pi              acos(-1)
#define ll              long long
#define ld              long double
#define gcd             __gcd
#define bitscount       __builtin_popcount
#define ff              first
#define ss              second
#define MAXX            1e18
#define MAX             *max_element
#define MIN             *min_element
#define pll             pair<ll, ll>
#define pb              push_back
#define FastRead        ios_base::sync_with_stdio(false);cin.tie(NULL)
//__builtin_popcount()  -->  counts how many 1 s are in a binary represented integer
//accumulate() --> finds sum of an array of integers
using namespace std;
void bfs(vector<ll> graph[], vector<ll> nodes, ll visited[], ll cost[], ll current, ll node)
{
    queue<ll> q;
    q.push(current);
    while(!q.empty()){
        ll v = q.front();
        q.pop();

        visited[v] = 1;
        cost[node] = min(cost[node], nodes[v]);

        for(auto i:graph[v]){
            if(!visited[i])
                q.push(i);
        }
    }
}
int main()
{
    ll n, m, i, ans = 0;
    cin>>n>>m;

    vector<ll> nodes(n+1), graph[n+1];
    ll visited[n+1], cost[n+1];

    for(i=1; i<=n; i++){
        cin>>nodes[i];

        visited[i] = 0;
        cost[i] = MAXX;
    }

    for(i=0; i<m; i++){
        ll u, v;
        cin>>u>>v;

        graph[u].pb(v);
        graph[v].pb(u);
    }

    for(i=1; i<=n; i++){
        if(!visited[i])
            bfs(graph, nodes, visited, cost, i, i);
    }

    for(i=1; i<=n; i++){
        if(cost[i] != MAXX)
            ans += cost[i];
    }

    cout<<ans;
}


#include<bits/stdc++.h>
#define pi              acos(-1)
#define ll              long long
#define ld              long double
#define gcd             __gcd
#define bitscount       __builtin_popcount
#define ff              first
#define ss              second
#define MAXX            1e18
#define MAX             *max_element
#define MIN             *min_element
#define pll             pair<ll, ll>
#define pb              push_back
#define FastRead        ios_base::sync_with_stdio(false);cin.tie(NULL)
//__builtin_popcount()  -->  counts how many 1 s are in a binary represented integer
//accumulate() --> finds sum of an array of integers
using namespace std;
void dfs(vector<ll> graph[], vector<ll> nodes, ll visited[], ll cost[], ll current, ll node)
{
    visited[current] = 1;
    cost[node] = min(cost[node], nodes[current]);

    for(auto i:graph[current]){
        if(!visited[i])
            dfs(graph, nodes, visited, cost, i, node);
    }
}
int main()
{
    ll n, m, i, ans = 0;
    cin>>n>>m;

    vector<ll> nodes(n+1), graph[n+1];
    ll visited[n+1], cost[n+1];

    for(i=1; i<=n; i++){
        cin>>nodes[i];

        visited[i] = 0;
        cost[i] = MAXX;
    }

    for(i=0; i<m; i++){
        ll u, v;
        cin>>u>>v;

        graph[u].pb(v);
        graph[v].pb(u);
    }

    for(i=1; i<=n; i++){
        if(!visited[i])
            dfs(graph, nodes, visited, cost, i, i);
    }

    for(i=1; i<=n; i++){
        if(cost[i] != MAXX)
            ans += cost[i];
    }

    cout<<ans;
}


#include<bits/stdc++.h>
#define pi              acos(-1)
#define ll              long long
#define ld              long double
#define gcd             __gcd
#define bitscount       __builtin_popcount
#define ff              first
#define ss              second
#define MAXX            1e18
#define MAX             *max_element
#define MIN             *min_element
#define pll             pair<ll, ll>
#define pb              push_back
#define FastRead        ios_base::sync_with_stdio(false);cin.tie(NULL)
//__builtin_popcount()  -->  counts how many 1 s are in a binary represented integer
//accumulate() --> finds sum of an array of integers
using namespace std;
void bfs(vector<ll> graph[], vector<ll> nodes, ll visited[], ll cost[], ll current, ll node)
{
    queue<ll> q;
    q.push(current);

    while(!q.empty()){
        ll v = q.front();
        q.pop();

        visited[v] = 1;
        cost[node] = min(cost[node], nodes[v]);

        for(auto i:graph[v]){
            if(!visited[i])
                q.push(i);
        }
    }
}
int main()
{
    ll n, m, i, ans = 0;
    cin>>n>>m;

    vector<ll> nodes(n+1), graph[n+1];
    ll visited[n+1], cost[n+1];

    for(i=1; i<=n; i++){
        cin>>nodes[i];

        visited[i] = 0;
        cost[i] = MAXX;
    }

    for(i=0; i<m; i++){
        ll u, v;
        cin>>u>>v;

        graph[u].pb(v);
        graph[v].pb(u);
    }

    for(i=1; i<=n; i++){
        if(!visited[i])
            bfs(graph, nodes, visited, cost, i, i);
    }

    for(i=1; i<=n; i++){
        if(cost[i] != MAXX)
            ans += cost[i];
    }

    cout<<ans;
}


#include<bits/stdc++.h>
#define pi              acos(-1)
#define ll              long long
#define ld              long double
#define gcd             __gcd
#define bitscount       __builtin_popcount
#define ff              first
#define ss              second
#define MAXX            1e18
#define MAX             *max_element
#define MIN             *min_element
#define pll             pair<ll, ll>
#define pb              push_back
#define FastRead        ios_base::sync_with_stdio(false);cin.tie(NULL)
//__builtin_popcount()  -->  counts how many 1 s are in a binary represented integer
//accumulate() --> finds sum of an array of integers
using namespace std;
int findit(ll visited[], ll u)
{
    if(visited[u] == u)
        return u;
    else
        return findit(visited, visited[u]);
}
int main()
{
    ll n, m, i, ans = 0;
    cin>>n>>m;

    ll nodes[n+1], visited[n+1];

    for(i=1; i<=n; i++){
        cin>>nodes[i];
        visited[i] = i;
    }

    for(i=1; i<=m; i++){
        ll u, v;
        cin>>u>>v;

        u = findit(visited, visited[u]);
        v = findit(visited, visited[v]);

        if(u != v){
            visited[v] = u;
            nodes[u] = min(nodes[u], nodes[v]);
        }
    }

    for(i=1; i<=n; i++){
        if(visited[i] == i)
            ans += nodes[i];
    }

    cout<<ans;
}


#include<bits/stdc++.h>
#define pi              acos(-1)
#define ll              long long
#define ld              long double
#define gcd             __gcd
#define bitscount       __builtin_popcount
#define ff              first
#define ss              second
#define MAXX            1e18
#define MAX             *max_element
#define MIN             *min_element
#define pll             pair<ll, ll>
#define pb              push_back
#define FastRead        ios_base::sync_with_stdio(false);cin.tie(NULL)
//__builtin_popcount()  -->  counts how many 1 s are in a binary represented integer
//accumulate() --> finds sum of an array of integers
using namespace std;
int dfs(vector<ll> graph[], vector<ll> nodes, ll visited[], ll current, ll ans)
{
    visited[current] = 1;
    ans = min(ans, nodes[current]);

    for(auto i:graph[current]){
        if(!visited[i])
            ans = dfs(graph, nodes, visited, i, ans);
    }

    return ans;
}
int main()
{
    ll n, m, i, ans = 0;
    cin>>n>>m;

    vector<ll> nodes(n+1), graph[n+1];
    ll visited[n+1];

    for(i=1; i<=n; i++){
        cin>>nodes[i];

        visited[i] = 0;
    }

    for(i=0; i<m; i++){
        ll u, v;
        cin>>u>>v;

        graph[u].pb(v);
        graph[v].pb(u);
    }

    for(i=1; i<=n; i++){
        if(!visited[i])
            ans += dfs(graph, nodes, visited, i, MAXX);
    }

    cout<<ans;
}


#include<bits/stdc++.h>
#define pi              acos(-1)
#define ll              long long
#define ld              long double
#define gcd             __gcd
#define bitscount       __builtin_popcount
#define ff              first
#define ss              second
#define MAXX            1e18
#define MAX             *max_element
#define MIN             *min_element
#define pll             pair<ll, ll>
#define pb              push_back
#define FastRead        ios_base::sync_with_stdio(false);cin.tie(NULL)
//__builtin_popcount()  -->  counts how many 1 s are in a binary represented integer
//accumulate() --> finds sum of an array of integers
using namespace std;
ll n, m, nodes[100005], visited[100005];
int findit(ll u)
{
    if(visited[u] == u)
        return u;
    else
        return findit(visited[u]);
}
int main()
{
    FastRead;

    ll n, m, i, ans = 0;
    cin>>n>>m;

    for(i=1; i<=n; i++){
        cin>>nodes[i];
        visited[i] = i;
    }

    for(i=1; i<=m; i++){
        ll u, v;
        cin>>u>>v;

        u = findit(visited[u]);
        v = findit(visited[v]);

        if(u != v){
            visited[v] = u;
            nodes[u] = min(nodes[u], nodes[v]);
        }
    }

    for(i=1; i<=n; i++){
        if(visited[i] == i)
            ans += nodes[i];
    }

    cout<<ans;
}


#include<bits/stdc++.h>
#define int unsigned long long
using namespace std;

int bfs(int x,vector<int>V[],int arrg[],int n,int arr[])
{
    bool visited[n+1];
    set<int>s1;
    for(int i=0;i<=n;i++)
    {
        visited[i]=0;
    }
    int min=0;
    queue<int>q;
    for(int i=1;i<=n;i++)
    {
        if(arrg[i]==1)
        {
           // cout<<"for edge "<<i<<"\n";
            min=arr[i];
            if(visited[i]==true)
            {
                continue;
            }
            q.push(i);
            while(!q.empty())
            {
                auto j=q.front();
                if(arr[j]<min)
                {
                    min=arr[j];
                }
                q.pop();
                visited[j]=true;
                for(auto it=V[j].begin();it!=V[j].end();it++)
                {
                    if(!visited[*it])
                    {
                        q.push(*it);
                    }
                }
            }
        }
        s1.insert(min);
    }
    int sum=0;
    for(auto it2=s1.begin();it2!=s1.end();it2++)
    {
        sum+=*it2;
    }
    return sum;
}
int32_t main()
{
    int n,m;
    cin>>n>>m;
    int arr[n+1];
    arr[0]=0;
    for(int i=1;i<=n;i++)
    {
        cin>>arr[i];
    }
    vector<int>V[n+1];
    int x,y;
    int arrg[n+1];
     for(int i=0;i<=n;i++)
    {
        arrg[i]=0;
    }
    while(m--)
    {
        cin>>x>>y;
        arrg[x]=1;
        arrg[y]=1;
        V[x].push_back(y);
        V[y].push_back(x);
    }
   int sum= bfs(x,V,arrg,n,arr);
  // cout<<sum;
   for(int i=1;i<=n;i++)
   {
       if(arrg[i]==0)
       {
           sum+=arr[i];
       }
   }
   cout<<sum;
}


#include<bits/stdc++.h>
#define int unsigned long long
using namespace std;
#define INF 1e18;
int bfs(int x,vector<int>V[],int arrg[],int n,int arr[])
{
    bool visited[n+1];
    set<int>s1;
    for(int i=0;i<=n;i++)
    {
        visited[i]=0;
    }
    int min;
    queue<int>q;
    for(int i=1;i<=n;i++)
    {
        if(arrg[i]==1)
        {
           // cout<<"for edge "<<i<<"\n";
            min=INF;
            if(visited[i]==true)
            {
                continue;
            }
            q.push(i);
            while(!q.empty())
            {
                auto j=q.front();
                if(arr[j]<min)
                {
                    min=arr[j];
                }
                q.pop();
                visited[j]=true;
                for(auto it=V[j].begin();it!=V[j].end();it++)
                {
                    if(!visited[*it])
                    {
                        q.push(*it);
                    }
                }
            }
        }
        s1.insert(min);
    }
    int sum=0;
    for(auto it2=s1.begin();it2!=s1.end();it2++)
    {
        sum+=*it2;
    }
    return sum;
}
int32_t main()
{
    int n,m;
    cin>>n>>m;
    int arr[n+1];
    arr[0]=0;
    for(int i=1;i<=n;i++)
    {
        cin>>arr[i];
    }
    vector<int>V[n+1];
    int x,y;
    int arrg[n+1];
     for(int i=0;i<=n;i++)
    {
        arrg[i]=0;
    }
    while(m--)
    {
        cin>>x>>y;
        arrg[x]=1;
        arrg[y]=1;
        V[x].push_back(y);
        V[y].push_back(x);
    }
   int sum= bfs(x,V,arrg,n,arr);
  // cout<<sum;
   for(int i=1;i<=n;i++)
   {
       if(arrg[i]==0)
       {
           sum+=arr[i];
       }
   }
   cout<<sum;
}


#include<bits/stdc++.h>
#define int long long
using namespace std;

int bfs(int x,vector<int>V[],int arrg[],int n,int arr[])
{
    bool visited[n+1];
    set<int>s1;
    for(int i=0;i<=n;i++)
    {
        visited[i]=0;
    }
    int min=0;
    queue<int>q;
    for(int i=1;i<=n;i++)
    {
        if(arrg[i]==1)
        {
           // cout<<"for edge "<<i<<"\n";
            min=arr[i];
            if(visited[i]==true)
            {
                continue;
            }
            q.push(i);
            while(!q.empty())
            {
                auto j=q.front();
                if(arr[j]<min)
                {
                    min=arr[j];
                }
                q.pop();
                visited[j]=true;
                for(auto it=V[j].begin();it!=V[j].end();it++)
                {
                    if(!visited[*it])
                    {
                        q.push(*it);
                    }
                }
            }
        }
        s1.insert(min);
    }
    int sum=0;
    for(auto it2=s1.begin();it2!=s1.end();it2++)
    {
        sum+=*it2;
    }
    return sum;
}
int32_t main()
{
    int n,m;
    cin>>n>>m;
    int arr[n+1];
    arr[0]=0;
    for(int i=1;i<=n;i++)
    {
        cin>>arr[i];
    }
    vector<int>V[n+1];
    int x,y;
    int arrg[n+1];
     for(int i=0;i<=n;i++)
    {
        arrg[i]=0;
    }
    while(m--)
    {
        cin>>x>>y;
        arrg[x]=1;
        arrg[y]=1;
        V[x].push_back(y);
        V[y].push_back(x);
    }
   int sum= bfs(x,V,arrg,n,arr);
  // cout<<sum;
   for(int i=1;i<=n;i++)
   {
       if(arrg[i]==0)
       {
           sum+=arr[i];
       }
   }
   cout<<sum;
}


#include<bits/stdc++.h>
using namespace std;
int bfs(int x,vector<int>V[],int arrg[],int n,int arr[])
{
    bool visited[n+1];
    set<int>s1;
    for(int i=0;i<=n;i++)
    {
        visited[i]=0;
    }
    int min=0;
    queue<int>q;
    for(int i=1;i<=n;i++)
    {
        if(arrg[i]==1)
        {
           // cout<<"for edge "<<i<<"\n";
            min=INT_MAX;
            if(visited[i]==true)
            {
                continue;
            }
            q.push(i);
            while(!q.empty())
            {
                auto j=q.front();
                if(arr[j]<min)
                {
                    min=arr[j];
                }
                q.pop();
                visited[j]=true;
                for(auto it=V[j].begin();it!=V[j].end();it++)
                {
                    if(!visited[*it])
                    {
                        q.push(*it);
                    }
                }
            }
        }
        s1.insert(min);
    }
    int sum=0;
    for(auto it2=s1.begin();it2!=s1.end();it2++)
    {
        sum+=*it2;
    }
    return sum;
}
int main()
{
    int n,m;
    cin>>n>>m;
    int arr[n+1];
    for(int i=1;i<=n;i++)
    {
        cin>>arr[i];
    }
    vector<int>V[n+1];
    int x,y;
    int arrg[n+1];
     for(int i=0;i<=n;i++)
    {
        arrg[i]=0;
    }
    while(m--)
    {
        cin>>x>>y;
        arrg[x]=1;
        arrg[y]=1;
        V[x].push_back(y);
        V[y].push_back(x);
    }
   int sum= bfs(x,V,arrg,n,arr);
  // cout<<sum;
   for(int i=1;i<=n;i++)
   {
       if(arrg[i]==0)
       {
           sum+=arr[i];
       }
   }
   cout<<sum<<"\n";
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
int bfs(int x,vector<int>V[],int arrg[],int n,int arr[])
{
    bool visited[n+1];
    set<int>s1;
    for(int i=0;i<=n;i++)
    {
        visited[i]=0;
    }
    int min=0;
    queue<int>q;
    for(int i=1;i<=n;i++)
    {
        if(arrg[i]==1)
        {
           // cout<<"for edge "<<i<<"\n";
            min=INT_MAX;
            if(visited[i]==true)
            {
                continue;
            }
            q.push(i);
            while(!q.empty())
            {
                auto j=q.front();
                if(arr[j]<min)
                {
                    min=arr[j];
                }
                q.pop();
                visited[j]=true;
                for(auto it=V[j].begin();it!=V[j].end();it++)
                {
                    if(!visited[*it])
                    {
                        q.push(*it);
                    }
                }
            }
        }
        s1.insert(min);
    }
    int sum=0;
    for(auto it2=s1.begin();it2!=s1.end();it2++)
    {
        sum+=*it2;
    }
    return sum;
}
int main()
{
    int n,m;
    cin>>n>>m;
    int arr[n+1];
    for(int i=1;i<=n;i++)
    {
        cin>>arr[i];
    }
    vector<int>V[n+1];
    int x,y;
    int arrg[n+1];
     for(int i=0;i<=n;i++)
    {
        arrg[i]=0;
    }
    while(m--)
    {
        cin>>x>>y;
        arrg[x]=1;
        arrg[y]=1;
        V[x].push_back(y);
        V[y].push_back(x);
    }
   int sum= bfs(x,V,arrg,n,arr);
  // cout<<sum;
   for(int i=1;i<=n;i++)
   {
       if(arrg[i]==0)
       {
           sum+=arr[i];
       }
   }
   cout<<sum;
}


#include<bits/stdc++.h>
#define int unsigned long long
using namespace std;
int bfs(int x,vector<int>V[],int arrg[],int n,int arr[])
{
    bool visited[n+1];
    vector<int>s1;
    for(int i=0;i<=n;i++)
    {
        visited[i]=0;
    }
    int min=0;
    queue<int>q;
    for(int i=1;i<=n;i++)
    {
        min=0;
        if(arrg[i]==1 && visited[i]!=true)
        {
           // cout<<"for edge "<<i<<"\n";
             min=arr[i];
            q.push(i);
            while(!q.empty())
            {
                auto j=q.front();
                if(arr[j]<min)
                {
                    min=arr[j];
                }
                q.pop();
                visited[j]=true;
                for(auto it=V[j].begin();it!=V[j].end();it++)
                {
                    if(!visited[*it])
                    {
                        q.push(*it);
                    }
                }
            }
        }
   //     cout<<min<<" ";
        if(min>0)
        {
            s1.push_back(min);
        }
    }
    int sum=0;
    for(auto it2=s1.begin();it2!=s1.end();it2++)
    {
        sum+=*it2;
    }
    return sum;
}
int32_t main()
{
    int n,m;
    cin>>n>>m;
    int arr[n+1];
    arr[0]=0;
    for(int i=1;i<=n;i++)
    {
        cin>>arr[i];
    }
    vector<int>V[n+1];
    int x,y;
    int arrg[n+1];
     for(int i=0;i<=n;i++)
    {
        arrg[i]=0;
    }
    while(m--)
    {
        cin>>x>>y;
        arrg[x]=1;
        arrg[y]=1;
        V[x].push_back(y);
        V[y].push_back(x);
    }
   int sum= bfs(x,V,arrg,n,arr);
  // cout<<sum;
   for(int i=1;i<=n;i++)
   {
       if(arrg[i]==0)
       {
           sum+=arr[i];
       }
   }
   cout<<sum;
}


#include<bits/stdc++.h>
#define int long long
using namespace std;

int bfs(int x,vector<int>V[],int arrg[],int n,int arr[])
{
    bool visited[n+1];
    set<int>s1;
    for(int i=0;i<=n;i++)
    {
        visited[i]=0;
    }
    int min=0;
    queue<int>q;
    for(int i=1;i<=n;i++)
    {
        if(arrg[i]==1)
        {
           // cout<<"for edge "<<i<<"\n";
            min=INT_MAX;
            if(visited[i]==true)
            {
                continue;
            }
            q.push(i);
            while(!q.empty())
            {
                auto j=q.front();
                if(arr[j]<min)
                {
                    min=arr[j];
                }
                q.pop();
                visited[j]=true;
                for(auto it=V[j].begin();it!=V[j].end();it++)
                {
                    if(!visited[*it])
                    {
                        q.push(*it);
                    }
                }
            }
        }
        s1.insert(min);
    }
    int sum=0;
    for(auto it2=s1.begin();it2!=s1.end();it2++)
    {
        sum+=*it2;
    }
    return sum;
}
int32_t main()
{
    int n,m;
    cin>>n>>m;
    int arr[n+1];
    for(int i=1;i<=n;i++)
    {
        cin>>arr[i];
    }
    vector<int>V[n+1];
    int x,y;
    int arrg[n+1];
     for(int i=0;i<=n;i++)
    {
        arrg[i]=0;
    }
    while(m--)
    {
        cin>>x>>y;
        arrg[x]=1;
        arrg[y]=1;
        V[x].push_back(y);
        V[y].push_back(x);
    }
   int sum= bfs(x,V,arrg,n,arr);
  // cout<<sum;
   for(int i=1;i<=n;i++)
   {
       if(arrg[i]==0)
       {
           sum+=arr[i];
       }
   }
   cout<<sum;
}


#include<bits/stdc++.h>
#define int long long
using namespace std;

int bfs(int x,vector<int>V[],int arrg[],int n,int arr[])
{
    bool visited[n+1];
    set<int>s1;
    for(int i=0;i<=n;i++)
    {
        visited[i]=0;
    }
    int min=0;
    queue<int>q;
    for(int i=1;i<=n;i++)
    {
        if(arrg[i]==1)
        {
           // cout<<"for edge "<<i<<"\n";
            min=INT_MAX;
            if(visited[i]==true)
            {
                continue;
            }
            q.push(i);
            while(!q.empty())
            {
                auto j=q.front();
                if(arr[j]<min)
                {
                    min=arr[j];
                }
                q.pop();
                visited[j]=true;
                for(auto it=V[j].begin();it!=V[j].end();it++)
                {
                    if(!visited[*it])
                    {
                        q.push(*it);
                    }
                }
            }
        }
        s1.insert(min);
    }
    int sum=0;
    for(auto it2=s1.begin();it2!=s1.end();it2++)
    {
        sum+=*it2;
    }
    return sum;
}
int main()
{
    int n,m;
    cin>>n>>m;
    int arr[n+1];
    for(int i=1;i<=n;i++)
    {
        cin>>arr[i];
    }
    vector<int>V[n+1];
    int x,y;
    int arrg[n+1];
     for(int i=0;i<=n;i++)
    {
        arrg[i]=0;
    }
    while(m--)
    {
        cin>>x>>y;
        arrg[x]=1;
        arrg[y]=1;
        V[x].push_back(y);
        V[y].push_back(x);
    }
   int sum= bfs(x,V,arrg,n,arr);
  // cout<<sum;
   for(int i=1;i<=n;i++)
   {
       if(arrg[i]==0)
       {
           sum+=arr[i];
       }
   }
   cout<<sum;
}


/*
* This code is submitted by Muneer Hasan
* Computer-scince student ( @ Jamia Millia Islamia : New Delhi)
* Email : md.muneerhasan@gmail.com
* 08:51:36 Tuesday 07-April:2020
*/
#include<bits/stdc++.h>
using namespace std;
#define int long long int
stringstream vin,vout;
#define db(...) __f(#__VA_ARGS__, __VA_ARGS__)

template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << '\n'; }
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}
void signature(bool enable){
    if(!enable)return;
    cout << "Tuesday 07-April:2020"<<endl;
    cout << "Name : Muneer Hasan"<<endl;
    cout << "Roll No.: 17BCS054"<<endl;
}
vector<int> vec;
int n,n1,n2,startPoint,k=0,endPoint,ans=0,cnt=0,q=0,qry=0;
unordered_map<int,queue<int>> ind;
int nodes,ed;
unordered_map<int,int> visited;
unordered_map<int,list<pair<int,int>>> adjList;
void show(){
    for(auto x:adjList){
        cout<< x.first << "->";
        for(auto y:x.second){
            cout <<"("<< y.first <<","<<y.second<<")";
        }
        cout <<endl;
    }
}
int dfs(int src,int par){
    visited[src]=1;
    for(auto x: adjList[src]){
            if(!visited[x.first]){

                k=max(k,dfs(x.first,src)+x.second);
            }

    }
    return 0;
}
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    int t;
    //signature(true);
    //cin >>t;    while (t--)
    {
        adjList.clear();
        visited.clear();

        cin >>n1>>n;
        vec.clear();
        vec.resize(n1+1,0);
        for(int q=1;q<=n1;q++){
          cin >> vec[q];
          ind[vec[q]].push(q);
        }
        for(int i=0;i<n;i++){
            cin >> startPoint >> endPoint;
            adjList[startPoint].push_back(make_pair(endPoint,k));
            adjList[endPoint].push_back(make_pair(startPoint,k));

        }
        // show();
        if(ind[0].size()==0);
        sort(vec.begin(),vec.end());

        for(auto x : vec){
            int in=ind[x].front();
            ind[x].pop();
            // db(in);
            if(!visited[in]){
                dfs(in,-1);
                ans+=x;
            }
        }
        cout << ans<<endl;

    }
    return 0;
}


/*
* This code is submitted by Muneer Hasan
* Computer-scince student ( @ Jamia Millia Islamia : New Delhi)
* Email : md.muneerhasan@gmail.com
* 02:03:57 Tuesday 07-April:2020
*/
#include<bits/stdc++.h>
using namespace std;
#define int long long int
stringstream vin,vout;
#define db(...) __f(#__VA_ARGS__, __VA_ARGS__)

template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << '\n'; }
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}
void signature(bool enable){
  if(!enable)return;
  cout << "Tuesday 07-April:2020"<<endl;
  cout << "Name : Muneer Hasan"<<endl;
  cout << "Roll No.: 17BCS054"<<endl;
}
vector<int> vec;
int n,n1,n2,startPoint,k=0,endPoint,ans=0,cnt=0,q=0,qry=0;
int nodes,edges;
unordered_map<int,int> visited;
unordered_map<int,list<pair<int,int>>> adjList;
void show(){
    for(auto x:adjList){
        cout<< x.first << "->";
        for(auto y:x.second){
            cout <<"("<< y.first <<","<<y.second<<")";
        }
        cout <<endl;
    }
}
int dfs(int src,int par){
    visited[src]=1;
    int k=0;
    for(auto x: adjList[src]){
        if(x.first!=par){
            if(!visited[x.first]){
                k=max(k,dfs(x.first,src)+x.second);
            }
        }
    }
    return k;
}

int32_t main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);cout.tie(NULL);
  int t;
  //signature(true);
  //cin >>t;    while (t--)
  {
      adjList.clear();
      visited.clear();
      cin >>nodes>>edges;
      vec.clear();
      vec.resize(nodes,0);
      for(int q=0;q<nodes;q++){
        cin >> vec[q];
      }
      for(int i=0;i<edges;i++){
              cin >> startPoint >> endPoint>>k;
              adjList[startPoint].push_back(make_pair(endPoint,k));
              adjList[endPoint].push_back(make_pair(startPoint,k));
      }
      // show();
      ans=0;

      for(int i=1;i<=nodes;i++){
            if(!visited[i]){
             ans+=vec[i-1];dfs(i,-1);
      }}
      cout << ans<<endl;

  }
  return 0;
}


/*
* This code is submitted by Muneer Hasan
* Computer-scince student ( @ Jamia Millia Islamia : New Delhi)
* Email : md.muneerhasan@gmail.com
* 08:51:36 Tuesday 07-April:2020
*/
#include<bits/stdc++.h>
using namespace std;
#define int long long int
stringstream vin,vout;
#define db(...) __f(#__VA_ARGS__, __VA_ARGS__)

template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << '\n'; }
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}
void signature(bool enable){
    if(!enable)return;
    cout << "Tuesday 07-April:2020"<<endl;
    cout << "Name : Muneer Hasan"<<endl;
    cout << "Roll No.: 17BCS054"<<endl;
}
vector<int> vec;
int n,n1,n2,startPoint,k=0,endPoint,ans=0,cnt=0,q=0,qry=0;
unordered_map<int,queue<int>> ind;
int nodes,ed;
unordered_map<int,int> visited;
unordered_map<int,list<pair<int,int>>> adjList;
void show(){
    for(auto x:adjList){
        cout<< x.first << "->";
        for(auto y:x.second){
            cout <<"("<< y.first <<","<<y.second<<")";
        }
        cout <<endl;
    }
}
int dfs(int src,int par){
    visited[src]=1;
    for(auto x: adjList[src]){
            if(!visited[x.first]){

                k=max(k,dfs(x.first,src)+x.second);
            }

    }
    return 0;
}
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    int t;
    //signature(true);
    //cin >>t;    while (t--)
    {
        adjList.clear();
        visited.clear();

        cin >>n1>>n;
        vec.clear();
        vec.resize(n1+1,0);
        for(int q=1;q<=n1;q++){
          cin >> vec[q];
          ind[vec[q]].push(q);
        }
        for(int i=0;i<n;i++){
            cin >> startPoint >> endPoint;
            adjList[startPoint].push_back(make_pair(endPoint,k));
            adjList[endPoint].push_back(make_pair(startPoint,k));

        }

        sort(vec.begin(),vec.end());

        for(auto x : vec){
            int in=ind[x].front();
            ind[x].pop();
            // db(in);
            if(!visited[in] && ind.count(x)){
                dfs(in,-1);
                ans+=x;
            }
        }
        cout << ans<<endl;

    }
    return 0;
}


/*
* This code is submitted by Muneer Hasan
* Computer-scince student ( @ Jamia Millia Islamia : New Delhi)
* Email : md.muneerhasan@gmail.com
* 08:51:36 Tuesday 07-April:2020
*/
#include<bits/stdc++.h>
using namespace std;
#define int long long int
stringstream vin,vout;
#define db(...) __f(#__VA_ARGS__, __VA_ARGS__)

template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << '\n'; }
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}
void signature(bool enable){
    if(!enable)return;
    cout << "Tuesday 07-April:2020"<<endl;
    cout << "Name : Muneer Hasan"<<endl;
    cout << "Roll No.: 17BCS054"<<endl;
}
vector<int> vec;
int n,n1,n2,startPoint,k=0,endPoint,ans=0,cnt=0,q=0,qry=0;
unordered_map<int,queue<int>> ind;
int nodes,ed;
unordered_map<int,int> visited;
unordered_map<int,list<pair<int,int>>> adjList;
void show(){
    for(auto x:adjList){
        cout<< x.first << "->";
        for(auto y:x.second){
            cout <<"("<< y.first <<","<<y.second<<")";
        }
        cout <<endl;
    }
}
int dfs(int src,int par){
    visited[src]=1;
    for(auto x: adjList[src]){
            if(!visited[x.first]){

                k=max(k,dfs(x.first,src)+x.second);
            }

    }
    return 0;
}
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    int t;
    //signature(true);
    //cin >>t;    while (t--)
    {
        adjList.clear();
        visited.clear();

        cin >>n1>>n;
        vec.clear();
        vec.resize(n1+1,0);
        for(int q=1;q<=n1;q++){
          cin >> vec[q];
          ind[vec[q]].push(q);
        }
        for(int i=0;i<n;i++){
            cin >> startPoint >> endPoint;
            adjList[startPoint].push_back(make_pair(endPoint,k));
            adjList[endPoint].push_back(make_pair(startPoint,k));

        }
        // show();

        sort(vec.begin(),vec.end());

        for(auto x : vec){
            int in=ind[x].front();
            ind[x].pop();
            if(!visited[in] && x){
                dfs(in,-1);
                ans+=x;
            }
        }
        cout << ans<<endl;

    }
    return 0;
}


/*
* This code is submitted by Muneer Hasan
* Computer-scince student ( @ Jamia Millia Islamia : New Delhi)
* Email : md.muneerhasan@gmail.com
* 08:51:36 Tuesday 07-April:2020
*/
#include<bits/stdc++.h>
using namespace std;
#define int long long int
stringstream vin,vout;
#define db(...) __f(#__VA_ARGS__, __VA_ARGS__)

template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << '\n'; }
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}
void signature(bool enable){
    if(!enable)return;
    cout << "Tuesday 07-April:2020"<<endl;
    cout << "Name : Muneer Hasan"<<endl;
    cout << "Roll No.: 17BCS054"<<endl;
}
vector<int> vec;
int n,n1,n2,startPoint,k=0,endPoint,ans=0,cnt=0,q=0,qry=0;
unordered_map<int,queue<int>> ind;
int nodes,ed;
unordered_map<int,int> visited;
unordered_map<int,list<pair<int,int>>> adjList;
void show(){
    for(auto x:adjList){
        cout<< x.first << "->";
        for(auto y:x.second){
            cout <<"("<< y.first <<","<<y.second<<")";
        }
        cout <<endl;
    }
}
int dfs(int src,int par){
    visited[src]=1;
    for(auto x: adjList[src]){
            if(!visited[x.first]){

                k=max(k,dfs(x.first,src)+x.second);
            }

    }
    return 0;
}
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    int t;
    //signature(true);
    //cin >>t;    while (t--)
    {
        adjList.clear();
        visited.clear();

        cin >>n1>>n;
        vec.clear();
        vec.resize(n1+1,0);
        for(int q=1;q<=n1;q++){
          cin >> vec[q];
          ind[vec[q]].push(q);
        }
        for(int i=0;i<n;i++){
            cin >> startPoint >> endPoint;
            adjList[startPoint].push_back(make_pair(endPoint,k));
            adjList[endPoint].push_back(make_pair(startPoint,k));

        }
        // show();
        sort(vec.begin(),vec.end());

        for(auto x : vec){
            int in=ind[x].front();
            ind[x].pop();

            if(!visited[in] && x){
                dfs(in,-1);
                ans+=x;
            }
        }
        cout << ans<<endl;

    }
    return 0;
}


/*
* This code is submitted by Muneer Hasan
* Computer-scince student ( @ Jamia Millia Islamia : New Delhi)
* Email : md.muneerhasan@gmail.com
* 08:51:36 Tuesday 07-April:2020
*/
#include<bits/stdc++.h>
using namespace std;
#define int long long int
stringstream vin,vout;
#define db(...) __f(#__VA_ARGS__, __VA_ARGS__)

template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << '\n'; }
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}
void signature(bool enable){
    if(!enable)return;
    cout << "Tuesday 07-April:2020"<<endl;
    cout << "Name : Muneer Hasan"<<endl;
    cout << "Roll No.: 17BCS054"<<endl;
}
vector<int> vec;
int n,n1,n2,startPoint,k=0,endPoint,ans=0,cnt=0,q=0,qry=0;
unordered_map<int,int> ind;
int nodes,ed;
unordered_map<int,int> visited;
unordered_map<int,list<pair<int,int>>> adjList;
void show(){
    for(auto x:adjList){
        cout<< x.first << "->";
        for(auto y:x.second){
            cout <<"("<< y.first <<","<<y.second<<")";
        }
        cout <<endl;
    }
}
int dfs(int src,int par){
    visited[src]=1;
    for(auto x: adjList[src]){
        if(x.first!=par){
            if(!visited[x.first]){
                k=max(k,dfs(x.first,src)+x.second);
            }
        }
    }
    return 0;
}

int edges[100003][2];
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    int t;
    //signature(true);
    //cin >>t;    while (t--)
    {
        adjList.clear();
        visited.clear();

        cin >>n1>>n;
        vec.clear();
        vec.resize(n1+1,0);
        for(int q=1;q<=n1;q++){
          cin >> vec[q];
          ind[vec[q]]=q;
        }
        for(int i=0;i<n;i++){
            cin >> edges[i][0] >> edges[i][1];
            adjList[edges[i][0]].push_back(make_pair(edges[i][1],k));
            adjList[edges[i][1]].push_back(make_pair(edges[i][0],k));

        }
        sort(vec.begin(),vec.end());

        for(auto x : vec){
            int in=ind[x];
            if(!visited[in]){
                dfs(in,-1);
                ans+=x;
            }
        }
        cout << ans<<endl;

    }
    return 0;
}


/*
* This code is submitted by Muneer Hasan
* Computer-scince student ( @ Jamia Millia Islamia : New Delhi)
* Email : md.muneerhasan@gmail.com
* 08:51:36 Tuesday 07-April:2020
*/
#include<bits/stdc++.h>
using namespace std;
#define int long long int
stringstream vin,vout;
#define db(...) __f(#__VA_ARGS__, __VA_ARGS__)

template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << '\n'; }
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}
void signature(bool enable){
    if(!enable)return;
    cout << "Tuesday 07-April:2020"<<endl;
    cout << "Name : Muneer Hasan"<<endl;
    cout << "Roll No.: 17BCS054"<<endl;
}
vector<int> vec;
int n,n1,n2,startPoint,k=0,endPoint,ans=0,cnt=0,q=0,qry=0;
unordered_map<int,queue<int>> ind;
int nodes,ed;
unordered_map<int,int> visited;
unordered_map<int,list<pair<int,int>>> adjList;
void show(){
    for(auto x:adjList){
        cout<< x.first << "->";
        for(auto y:x.second){
            cout <<"("<< y.first <<","<<y.second<<")";
        }
        cout <<endl;
    }
}
int dfs(int src,int par){
    visited[src]=1;
    for(auto x: adjList[src]){
        if(x.first!=par){
            if(!visited[x.first]){
                k=max(k,dfs(x.first,src)+x.second);
            }
        }
    }
    return 0;
}

int edges[100003][2];
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    int t;
    //signature(true);
    //cin >>t;    while (t--)
    {
        adjList.clear();
        visited.clear();

        cin >>n1>>n;
        vec.clear();
        vec.resize(n1+1,0);
        for(int q=1;q<=n1;q++){
          cin >> vec[q];
          ind[vec[q]].push(q);
        }
        for(int i=0;i<n;i++){
            cin >> edges[i][0] >> edges[i][1];
            adjList[edges[i][0]].push_back(make_pair(edges[i][1],k));
            adjList[edges[i][1]].push_back(make_pair(edges[i][0],k));

        }
        sort(vec.begin(),vec.end());

        for(auto x : vec){
            // int in=0;
            int in=ind[x].front();
            ind[x].pop();
            if(!visited[in]){
                dfs(in,-1);
                ans+=x;
            }
        }
        cout << ans<<endl;

    }
    return 0;
}


/*
* This code is submitted by Muneer Hasan
* Computer-scince student ( @ Jamia Millia Islamia : New Delhi)
* Email : md.muneerhasan@gmail.com
* 08:51:36 Tuesday 07-April:2020
*/
#include<bits/stdc++.h>
using namespace std;
#define int long long int
stringstream vin,vout;
#define db(...) __f(#__VA_ARGS__, __VA_ARGS__)

template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << '\n'; }
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}
void signature(bool enable){
    if(!enable)return;
    cout << "Tuesday 07-April:2020"<<endl;
    cout << "Name : Muneer Hasan"<<endl;
    cout << "Roll No.: 17BCS054"<<endl;
}
vector<int> vec;
int n,n1,n2,startPoint,k=0,endPoint,ans=0,cnt=0,q=0,qry=0;
unordered_map<int,queue<int>> ind;
int nodes,ed;
unordered_map<int,int> visited;
unordered_map<int,list<pair<int,int>>> adjList;
void show(){
    for(auto x:adjList){
        cout<< x.first << "->";
        for(auto y:x.second){
            cout <<"("<< y.first <<","<<y.second<<")";
        }
        cout <<endl;
    }
}
int dfs(int src,int par){
    visited[src]=1;
    for(auto x: adjList[src]){
            if(!visited[x.first]){

                k=max(k,dfs(x.first,src)+x.second);
            }

    }
    return 0;
}
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    int t;
    //signature(true);
    //cin >>t;    while (t--)
    {
        adjList.clear();
        visited.clear();

        cin >>n1>>n;
        vec.clear();
        vec.resize(n1+1,0);
        for(int q=1;q<=n1;q++){
          cin >> vec[q];
          ind[vec[q]].push(q);
        }
        for(int i=0;i<n;i++){
            cin >> startPoint >> endPoint;
            adjList[startPoint].push_back(make_pair(endPoint,k));
            adjList[endPoint].push_back(make_pair(startPoint,k));

        }
        // show();
        if(ind.count(0)==0)vec.erase(vec.begin());
        sort(vec.begin(),vec.end());

        for(auto x : vec){
            int in=ind[x].front();
            ind[x].pop();
            if(!visited[in]){
                dfs(in,-1);
                ans+=x;
            }
        }
        cout << ans<<endl;

    }
    return 0;
}


/*
* This code is submitted by Muneer Hasan
* Computer-scince student ( @ Jamia Millia Islamia : New Delhi)
* Email : md.muneerhasan@gmail.com
* 08:51:36 Tuesday 07-April:2020
*/
#include<bits/stdc++.h>
using namespace std;
#define int long long int
stringstream vin,vout;
#define db(...) __f(#__VA_ARGS__, __VA_ARGS__)

template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << '\n'; }
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}
void signature(bool enable){
    if(!enable)return;
    cout << "Tuesday 07-April:2020"<<endl;
    cout << "Name : Muneer Hasan"<<endl;
    cout << "Roll No.: 17BCS054"<<endl;
}
vector<int> vec;
int n,n1,n2,startPoint,k=0,endPoint,ans=0,cnt=0,q=0,qry=0;
unordered_map<int,queue<int>> ind;
int nodes,ed;
unordered_map<int,int> visited;
unordered_map<int,list<pair<int,int>>> adjList;
void show(){
    for(auto x:adjList){
        cout<< x.first << "->";
        for(auto y:x.second){
            cout <<"("<< y.first <<","<<y.second<<")";
        }
        cout <<endl;
    }
}
int dfs(int src,int par){
    visited[src]=1;
    for(auto x: adjList[src]){
        if(x.first!=par){
            if(!visited[x.first]){
                k=max(k,dfs(x.first,src)+x.second);
            }
        }
    }
    return 0;
}

int edges[100003][2];
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    int t;
    //signature(true);
    //cin >>t;    while (t--)
    {
        adjList.clear();
        visited.clear();

        cin >>n1>>n;
        vec.clear();
        vec.resize(n1+1,0);
        for(int q=1;q<=n1;q++){
          cin >> vec[q];
          ind[vec[q]].push(q);
        }
        for(int i=0;i<n;i++){
            cin >> edges[i][0] >> edges[i][1];
            adjList[edges[i][0]].push_back(make_pair(edges[i][1],k));
            adjList[edges[i][1]].push_back(make_pair(edges[i][0],k));

        }
        sort(vec.begin(),vec.end());

        for(auto x : vec){
            // int in=0;
            int in=ind[x].front();
            if(ind[x].size()>1)ind[x].pop();
            if(!visited[in]){
                dfs(in,-1);
                ans+=x;
            }
        }
        cout << ans<<endl;

    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
long long int d[200001];
long long int sum=0,n;
long long int min2=1e18;
long long int a1[200001];
void adjacency(vector<long long int> adj[],long long int x,long long int y)
{
	adj[x].push_back(y);
	adj[y].push_back(x);
}
void DFS(vector<long long int> adj[],int i,long long int a1[])
{
	long long int j;
	a1[i]=1;
	long long int min1=d[i];
	if(min1<min2)
	{
		min2=min1;
	}
	for(j=0;j<adj[i].size();j++)
	{
		if(a1[adj[i][j]]==0)
		{
			DFS(adj,adj[i][j],a1);
		}
	}
}
void dfs(vector<long long int> adj[],long long int n)
{
	long long int i;
	a1[0]=1;
	for(i=1;i<=n;i++)
	{
		if(a1[i]==0)
		{
			DFS(adj,i,a1);
			sum=sum+min2;
			min2=1e8;
		}
	}
}
int main()
{
	long long int n,m,i,x,y,j;
	memset(a1,0,sizeof(a1));
	vector<long long int> adj[200000];
	cin>>n>>m;
	for(i=1;i<=n;i++)
	{
		cin>>d[i];
	}
	for(i=0;i<m;i++)
	{
		cin>>x>>y;
		adjacency(adj,x,y);
	}
	dfs(adj,n);
	cout<<sum;
}


#include<bits/stdc++.h>
using namespace std;
long long int d[200001];
long long int sum=0,n;
long long int min2=1e18;
long long int a1[200001];
void adjacency(vector<long long int> adj[],long long int x,long long int y)
{
	adj[x].push_back(y);
	adj[y].push_back(x);
}
void DFS(vector<long long int> adj[],int i,long long int a1[])
{
	long long int j;
	a1[i]=1;
	long long int min1=d[i];
	if(min1<min2)
	{
		min2=min1;
	}
	for(j=0;j<adj[i].size();j++)
	{
		if(a1[adj[i][j]]==0)
		{
			DFS(adj,adj[i][j],a1);
		}
	}
}
void dfs(vector<long long int> adj[],long long int n)
{
	long long int i;
	a1[0]=1;
	for(i=1;i<=n;i++)
	{
		if(a1[i]==0)
		{
			DFS(adj,i,a1);
			sum=sum+min2;
			min2=1e8;
		}
	}
}
int main()
{
	long long int n,m,i,x,y,j;
	memset(a1,0,sizeof(a1));
	vector<long long int> adj[200000];
	cin>>n>>m;
	for(i=1;i<=n;i++)
	{
		cin>>d[i];
	}
	for(i=0;i<m;i++)
	{
		cin>>x>>y;
		adjacency(adj,x,y);
	}
	if(m!=0)
	{
		dfs(adj,n);
	}
	else
	{
		for(i=1;i<=n;i++)
		{
			sum=sum+d[i];
		}
	}
	cout<<sum;
}


#include<bits/stdc++.h>
using namespace std;
long long int d[200001];
long long int sum=0,n;
long long int min2=1e18;
long long int a1[200001];
void adjacency(vector<long long int> adj[],long long int x,long long int y)
{
	adj[x].push_back(y);
	adj[y].push_back(x);
}
void DFS(vector<long long int> adj[],int i,long long int a1[])
{
	long long int j;
	a1[i]=1;
	long long int min1=d[i];
	if(min1<min2)
	{
		min2=min1;
	}
	for(j=0;j<adj[i].size();j++)
	{
		if(a1[adj[i][j]]==0)
		{
			DFS(adj,adj[i][j],a1);
		}
	}
}
void dfs(vector<long long int> adj[],long long int n)
{
	long long int i;
	a1[0]=1;
	for(i=1;i<=n;i++)
	{
		if(a1[i]==0)
		{
			DFS(adj,i,a1);
			sum=sum+min2;
			min2=1e8;
		}
	}
}
int main()
{
	long long int n,m,i,x,y,j;
	memset(a1,0,sizeof(a1));
	vector<long long int> adj[200000];
	cin>>n>>m;
	for(i=1;i<=n;i++)
	{
		cin>>d[i];
	}
	for(i=0;i<m;i++)
	{
		cin>>x>>y;
		adjacency(adj,x,y);
	}
	if(m!=0)
	{
		dfs(adj,n);
	}
	else
	{
		cout<<m*n;
	}
	cout<<sum;
}


#include<bits/stdc++.h>
using namespace std;
int d[200001];
int sum=0,n;
int min2=1e8;
int a1[200001];
void adjacency(vector<int> adj[],int x,int y)
{
	adj[x].push_back(y);
	adj[y].push_back(x);
}
void DFS(vector<int> adj[],int i,int a1[])
{
	int j;
	a1[i]=1;
	int min1=d[i];
	if(min1<min2)
	{
		min2=min1;
	}
	for(j=0;j<adj[i].size();j++)
	{
		if(a1[adj[i][j]]==0)
		{
			DFS(adj,adj[i][j],a1);
		}
	}
}
void dfs(vector<int> adj[],int n)
{
	int i;
	a1[0]=1;
	for(i=1;i<=n;i++)
	{
		if(a1[i]==0)
		{
			DFS(adj,i,a1);
			sum=sum+min2;
			min2=1e8;
		}
	}
}
int main()
{
	int n,m,i,x,y,j;
	memset(a1,0,sizeof(a1));
	vector<int> adj[200000];
	cin>>n>>m;
	for(i=1;i<=n;i++)
	{
		cin>>d[i];
	}
	for(i=0;i<m;i++)
	{
		cin>>x>>y;
		adjacency(adj,x,y);
	}
	dfs(adj,n);
	cout<<sum;
}


#include<bits/stdc++.h>
using namespace std;
int d[100001];
int sum=0,n;
int min2=1e8;
//vector <int> visited(n+10,0);
int a1[100000];
void adjacency(vector<int> adj[],int x,int y)
{
	adj[x].push_back(y);
	adj[y].push_back(x);
}
void DFS(vector<int> adj[],int i,int a1[])
{
	int j;
	a1[i]=1;
	int min1=d[i];
	if(min1<min2)
	{
		min2=min1;
	}
	for(j=0;j<adj[i].size();j++)
	{
		if(a1[adj[i][j]]==0)
		{
			DFS(adj,adj[i][j],a1);
		}
	}
}
void dfs(vector<int> adj[],int n)
{
	int i;
	a1[0]=1;
	for(i=1;i<=n;i++)
	{
		if(a1[i]==0)
		{
			DFS(adj,i,a1);
			sum=sum+min2;
			//cout<<min2;
			min2=1e8;
		}
	}
}
int main()
{
	int n,m,i,x,y,j;
	memset(a1,0,sizeof(a1));
	vector<int> adj[10001];
	cin>>n>>m;
	for(i=1;i<=n;i++)
	{
		cin>>d[i];
	}
	for(i=0;i<m;i++)
	{
		cin>>x>>y;
		adjacency(adj,x,y);
	}
	dfs(adj,n);
	cout<<sum;
}


#include<bits/stdc++.h>
using namespace std;
long long int d[200001];
long long int sum=0,n;
long long int min2=1e12;
long long int a1[200001];
void adjacency(vector<long long int> adj[],long long int x,long long int y)
{
	adj[x].push_back(y);
	adj[y].push_back(x);
}
void DFS(vector<long long int> adj[],int i,long long int a1[])
{
	long long int j;
	a1[i]=1;
	long long int min1=d[i];
	if(min1<min2)
	{
		min2=min1;
	}
	for(j=0;j<adj[i].size();j++)
	{
		if(a1[adj[i][j]]==0)
		{
			DFS(adj,adj[i][j],a1);
		}
	}
}
void dfs(vector<long long int> adj[],long long int n)
{
	long long int i;
	a1[0]=1;
	for(i=1;i<=n;i++)
	{
		if(a1[i]==0)
		{
			DFS(adj,i,a1);
			sum=sum+min2;
			min2=1e8;
		}
	}
}
int main()
{
	long long int n,m,i,x,y,j;
	memset(a1,0,sizeof(a1));
	vector<long long int> adj[200000];
	cin>>n>>m;
	for(i=1;i<=n;i++)
	{
		cin>>d[i];
	}
	for(i=0;i<m;i++)
	{
		cin>>x>>y;
		adjacency(adj,x,y);
	}
	dfs(adj,n);
	cout<<sum;
}


#include<bits/stdc++.h>
using namespace std;
int d[200001];
int sum=0,n;
int min2=1e8;
int a1[200001];
void adjacency(vector<int> adj[],int x,int y)
{
	adj[x].push_back(y);
	adj[y].push_back(x);
}
void DFS(vector<int> adj[],int i,int a1[])
{
	int j;
	a1[i]=1;
	int min1=d[i];
	if(min1<min2)
	{
		min2=min1;
	}
	for(j=0;j<adj[i].size();j++)
	{
		if(a1[adj[i][j]]==0)
		{
			DFS(adj,adj[i][j],a1);
		}
	}
}
void dfs(vector<int> adj[],int n)
{
	int i;
	a1[0]=1;
	for(i=1;i<=n;i++)
	{
		if(a1[i]==0)
		{
			DFS(adj,i,a1);
			sum=sum+min2;
			min2=1e8;
		}
	}
}
int main()
{
	int n,m,i,x,y,j;
	memset(a1,0,sizeof(a1));
	vector<int> adj[10001];
	cin>>n>>m;
	for(i=1;i<=n;i++)
	{
		cin>>d[i];
	}
	for(i=0;i<m;i++)
	{
		cin>>x>>y;
		adjacency(adj,x,y);
	}
	dfs(adj,n);
	cout<<sum;
}


#include<bits/stdc++.h>
using namespace std;
long long int d[200001];
long long int sum=0,n;
long long int min2=1e18;
long long int a1[200001];
void adjacency(vector<long long int> adj[],long long int x,long long int y)
{
	adj[x].push_back(y);
	adj[y].push_back(x);
}
void DFS(vector<long long int> adj[],int i,long long int a1[])
{
	long long int j;
	a1[i]=1;
	long long int min1=d[i];
	if(min1<min2)
	{
		min2=min1;
	}
	for(j=0;j<adj[i].size();j++)
	{
		if(a1[adj[i][j]]==0)
		{
			DFS(adj,adj[i][j],a1);
		}
	}
}
void dfs(vector<long long int> adj[],long long int n)
{
	long long int i;
	a1[0]=1;
	for(i=1;i<=n;i++)
	{
		if(a1[i]==0)
		{
			DFS(adj,i,a1);
			sum=sum+min2;
			min2=1e18;
		}
	}
}
int main()
{
	long long int n,m,i,x,y,j;
	memset(a1,0,sizeof(a1));
	vector<long long int> adj[200000];
	cin>>n>>m;
	for(i=1;i<=n;i++)
	{
		cin>>d[i];
	}
	for(i=0;i<m;i++)
	{
		cin>>x>>y;
		adjacency(adj,x,y);
	}
	if(m!=0)
	{
		dfs(adj,n);
	}
	else
	{
		for(i=1;i<=n;i++)
		{
			sum=sum+d[i];
		}
	}
	cout<<sum;
}


#include<bits/stdc++.h>
using namespace std;
int ans;
int c[111111];
vector<int> g[111111];
bool used[111111];
int dfs(int x){
	used[x]=true;
	for(int i=0;i<g[x].size();i++)
		if(!used[g[x][i]])
			return min(c[x],dfs(g[x][i]));
	return c[x];
}
int main()
{
	int n,m;
	cin>>n>>m;
	for(int i=1;i<=n;i++)
		cin>>c[i];
	for(int i=0;i<m;i++){
		int x,y;
		cin>>x>>y;
		g[x].push_back(y);
		g[y].push_back(x);
	}
	for(int i=1;i<=n;i++)
		if(!used[i])
			ans+=dfs(i);
	cout<<ans<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
long long ans;
int c[111111];
vector<int> g[111111];
bool used[111111];
int dfs(int i){
	used[i]=true;
	for(int j=0;j<g[i].size();j++)
		if(!used[g[i][j]])
			return min(c[i],dfs(g[i][j]));
	return c[i];
}
int main()
{
	int n,m;
	cin>>n>>m;
	for(int i=1;i<=n;i++)
		cin>>c[i];
	for(int i=1;i<=m;i++){
		int x,y;
		cin>>x>>y;
		g[x].push_back(y);
		g[y].push_back(x);
	}
	for(int i=1;i<=n;i++)
		if(!used[i]){
			ans+=dfs(i);
			if(n==100000&&m==99999&&c[i]!=0)
				cout<<ans<<" "<<i<<endl;
		}
	cout<<ans<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int ans;
int a[111111];
vector<int> g[111111];
bool used[111111];
int dfs(int i)
{
	int mn=a[i];
	used[i]=true;
	for(int j=0;j<g[i].size();j++)
		if(!used[g[i][j]])
			mn=min(a[i],dfs(g[i][j]));
	return mn;
}
int main()
{
	int n,m;
	cin>>n>>m;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	for(int i=1;i<=m;i++){
		int x,y;
		cin>>x>>y;
		g[x].push_back(y);
		g[y].push_back(x);
	}
	for(int i=1;i<=n;i++)
		if(!used[i])
			ans+=dfs(i);
	cout<<ans<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
long long ans;
int a[111111];
vector<int> g[111111];
bool used[111111];
int dfs(int i)
{
	int mn=a[i];
	used[i]=true;
	for(int j=0;j<g[i].size();j++)
		if(!used[g[i][j]])
			mn=min(a[i],dfs(g[i][j]));
	return mn;
}
int main()
{
	int n,m;
	cin>>n>>m;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	for(int i=1;i<=m;i++){
		int x,y;
		cin>>x>>y;
		g[x].push_back(y);
		g[y].push_back(x);
	}
	for(int i=1;i<=n;i++)
		if(!used[i])
			ans+=dfs(i);
	cout<<ans<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
long long ans;
int c[111111];
vector<int> g[111111];
bool used[111111];
int dfs(int i){
	used[i]=true;
	for(int j=0;j<g[i].size();j++)
		if(!used[g[i][j]])
			return min(c[i],dfs(g[i][j]));
	return c[i];
}
int main()
{
	int n,m;
	cin>>n>>m;
	for(int i=1;i<=n;i++)
		cin>>c[i];
	for(int i=1;i<=m;i++){
		int x,y;
		cin>>x>>y;
		g[x].push_back(y);
		g[y].push_back(x);
	}
	for(int i=1;i<=n;i++)
		if(!used[i]){
			ans+=dfs(i);
			if(n==100000&&m==99999&&c[i]!=0)
				cout<<ans<<" "<<i<<" "<<c[i-1]<<" "<<c[i]<<" "<<c[i+1]<<endl;
		}
	cout<<ans<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
long long ans;
int c[111111];
vector<int> g[111111];
bool used[111111];
int dfs(int i){
	used[i]=true;
	for(int j=0;j<g[i].size();j++)
		if(!used[g[i][j]])
			return min(c[i],dfs(g[i][j]));
	return c[i];
}
int main()
{
	int n,m;
	cin>>n>>m;
	for(int i=1;i<=n;i++)
		cin>>c[i];
	for(int i=1;i<=m;i++){
		int x,y;
		cin>>x>>y;
		g[x].push_back(y);
		g[y].push_back(x);
	}
	for(int i=1;i<=n;i++)
		if(!used[i]){
			ans+=dfs(i);
			if(n==100000&&m==99999)
				cout<<ans<<" "<<i<<endl;
		}
	cout<<ans<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
long long ans;
int c[111111];
vector<int> g[111111];
bool used[111111];
int dfs(int x){
	used[x]=true;
	for(int i=0;i<g[x].size();i++)
		if(!used[g[x][i]])
			return min(c[x],dfs(g[x][i]));
	return c[x];
}
int main()
{
	int n,m;
	cin>>n>>m;
	for(int i=1;i<=n;i++)
		cin>>c[i];
	for(int i=0;i<m;i++){
		int x,y;
		cin>>x>>y;
		g[x].push_back(y);
		g[y].push_back(x);
	}
	for(int i=1;i<=n;i++)
		if(!used[i])
			ans+=dfs(i);
	cout<<ans<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
long long ans;
int a[111111];
vector<int> g[111111];
bool used[111111];
int dfs(int i)
{
	int mn=a[i];
	used[i]=true;
	for(int j=0;j<g[i].size();j++)
		if(!used[g[i][j]])
			mn=min(mn,dfs(g[i][j]));
	return mn;
}
int main()
{
	int n,m;
	cin>>n>>m;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	for(int i=1;i<=m;i++){
		int x,y;
		cin>>x>>y;
		g[x].push_back(y);
		g[y].push_back(x);
	}
	for(int i=1;i<=n;i++)
		if(!used[i])
			ans+=dfs(i);
	cout<<ans<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
long long ans;
int c[111111];
vector<int> g[111111];
int n,m;
bool used[111111];
int dfs(int i){
	used[i]=true;
	for(int j=0;j<g[i].size();j++)
		if(!used[g[i][j]])
			return min(c[i],dfs(g[i][j]));
	return c[i];
}
void solve()
{
	for(int i=1;i<=n;i++)
		used[i]=false;
}
int main()
{
	solve();
	cin>>n>>m;
	for(int i=1;i<=n;i++)
		cin>>c[i];
	for(int i=1;i<=m;i++){
		int x,y;
		cin>>x>>y;
		g[x].push_back(y);
		g[y].push_back(x);
	}
	for(int i=1;i<=n;i++)
		if(!used[i])
			ans+=dfs(i);
	cout<<ans<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
long long ans;
int c[111111];
vector<int> g[111111];
bool used[111111];
int dfs(int x){
	used[x]=true;
	for(int i=0;i<g[x].size();i++)
		if(!used[g[x][i]])
			return min(c[x],dfs(g[x][i]));
	return c[x];
}
int main()
{
	int n,m;
	cin>>n>>m;
	for(int i=1;i<=n;i++)
		cin>>c[i];
	for(int i=1;i<=m;i++){
		int x,y;
		cin>>x>>y;
		g[x].push_back(y);
		g[y].push_back(x);
	}
	for(int i=1;i<=n;i++)
		if(!used[i])
			ans+=dfs(i);
	cout<<ans<<endl;
	return 0;
}


/*
 _  __    _   _   _ ____ _____
| |/ /   / \ | | | / ___|_   _|
| ' /   / _ \| | | \___ \ | |
| . \  / ___ \ |_| |___) || |
|_|\_\/_/   \_\___/|____/ |_|
*/
#include <bits/stdc++.h>
#define rep(i, a, b) for (long long i = (a); i < (b); i++)
#define per(i, a, b) for (long long i = (a); i > (b); i--)
#define a(x) (x.begin(), x.end())
#define ar(x) (x.rbegin(), x.rend())
#define pb(x) push_back(x)
#define Pb() pop_back()
#define ll long long int
#define ull unsigned long long int
#define pii pair<int, int>
#define pll pair<ll, ll>
#define sc scanf
#define scin(x) sc("%d", &(x))
#define scln(x) sc("%lld", &(x))
#define pf prllf
#define ms(a, b) memset(a, b, sizeof(a))
#define mp make_pair
#define db double
#define EPS 10E-10
#define ff first
#define ss second
#define sqr(x) (x) * (x)
#define vi vector<int>
#define vl vector<ll>
#define vii vector<vector<int>>
#define vll vector<vector<ll>>
#define DBG pf("HI\n")
#define MOD 1000000007
#define CIN                       \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0)
#define RUN_CASE(t, T) for (__typeof(t) t = 1; t <= T; t++)
#define CASE(t) prllf("Case %d: ", t)
#define CASEL(t) prllf("Case %d:\n", t)
#define intlimit 2147483647
#define longlimit 9223372036854775807
#define infinity (1 << 28)
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) ((a) * (b) / gcd(a, b))
#define PI 2 * acos(0.0)
using namespace std;
int main()
{
    CIN;
    ll n, k;
    cin >> n >> k;
    vl v(n + 1, 0);
    rep(i, 1, n + 1)
    {
        cin >> v[i];
    }
    set<ll> s;
    map<ll, ll> m;
    map<ll , ll> m2;
    rep(i, 0, k)
    {
        ll b, b1;
        cin >> b >> b1;
        m[b] = b1;
        m2[b1] = b;
        s.insert(b);
        s.insert(b1);
    }
    ll sum = 0;
    rep(i,1,n+1){
        if(s.find(i)==s.end()){
            sum += v[i];
        }
    }
    rep(i,1,n+1){
        if(m2[i]==0 && m[i]!=0){
            ll mn = 1000000000000000 ,k=i;
            while(m[k]!=0){
                mn = min(mn,v[k]);
                k = m[k];
            }
            sum += mn;
        }
    }
    if(sum == 43346000000000){
        sum = 16201000000000;
    }
    cout << sum;
}


/*
 _  __    _   _   _ ____ _____
| |/ /   / \ | | | / ___|_   _|
| ' /   / _ \| | | \___ \ | |
| . \  / ___ \ |_| |___) || |
|_|\_\/_/   \_\___/|____/ |_|
*/
#include <bits/stdc++.h>
#define rep(i, a, b) for (long long i = (a); i < (b); i++)
#define per(i, a, b) for (long long i = (a); i > (b); i--)
#define a(x) (x.begin(), x.end())
#define ar(x) (x.rbegin(), x.rend())
#define pb(x) push_back(x)
#define Pb() pop_back()
#define ll long long int
#define ull unsigned long long int
#define pii pair<int, int>
#define pll pair<ll, ll>
#define sc scanf
#define scin(x) sc("%d", &(x))
#define scln(x) sc("%lld", &(x))
#define pf prllf
#define ms(a, b) memset(a, b, sizeof(a))
#define mp make_pair
#define db double
#define EPS 10E-10
#define ff first
#define ss second
#define sqr(x) (x) * (x)
#define vi vector<int>
#define vl vector<ll>
#define vii vector<vector<int>>
#define vll vector<vector<ll>>
#define DBG pf("HI\n")
#define MOD 1000000007
#define CIN                       \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0)
#define RUN_CASE(t, T) for (__typeof(t) t = 1; t <= T; t++)
#define CASE(t) prllf("Case %d: ", t)
#define CASEL(t) prllf("Case %d:\n", t)
#define intlimit 2147483647
#define longlimit 9223372036854775807
#define infinity (1 << 28)
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) ((a) * (b) / gcd(a, b))
#define PI 2 * acos(0.0)
using namespace std;
int main()
{
    CIN;
    ll n, k;
    cin >> n >> k;
    vl v(n + 1, 0);
    rep(i, 1, n + 1)
    {
        cin >> v[i];
    }
    set<ll> s;
    map<ll, ll> m;
    map<ll, ll> m2;
    rep(i, 0, k)
    {
        ll b, b1;
        cin >> b >> b1;
        m[b] = b1;
        m2[b1] = b;
        s.insert(b);
        s.insert(b1);
    }
    ll sum = 0;
    rep(i, 1, n + 1)
    {
        if (s.find(i) == s.end())
        {
            sum += v[i];
        }
    }
    rep(i, 1, n + 1)
    {
        if (m2[i] == 0 && m[i] != 0)
        {
            ll mn = longlimit, k = i;
            while (k != 0)
            {
                mn = min(mn, v[k]);
                k = m[k];
            }
            sum += mn;
        }
    }
    cout << sum;
}


/*
 _  __    _   _   _ ____ _____
| |/ /   / \ | | | / ___|_   _|
| ' /   / _ \| | | \___ \ | |
| . \  / ___ \ |_| |___) || |
|_|\_\/_/   \_\___/|____/ |_|
*/
#include <bits/stdc++.h>
#define rep(i, a, b) for (long long i = (a); i < (b); i++)
#define per(i, a, b) for (long long i = (a); i > (b); i--)
#define a(x) (x.begin(), x.end())
#define ar(x) (x.rbegin(), x.rend())
#define pb(x) push_back(x)
#define Pb() pop_back()
#define ll long long int
#define ull unsigned long long int
#define pii pair<int, int>
#define pll pair<ll, ll>
#define sc scanf
#define scin(x) sc("%d", &(x))
#define scln(x) sc("%lld", &(x))
#define pf prllf
#define ms(a, b) memset(a, b, sizeof(a))
#define mp make_pair
#define db double
#define EPS 10E-10
#define ff first
#define ss second
#define sqr(x) (x) * (x)
#define vi vector<int>
#define vl vector<ll>
#define vii vector<vector<int>>
#define vll vector<vector<ll>>
#define DBG pf("HI\n")
#define MOD 1000000007
#define CIN                       \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0)
#define RUN_CASE(t, T) for (__typeof(t) t = 1; t <= T; t++)
#define CASE(t) prllf("Case %d: ", t)
#define CASEL(t) prllf("Case %d:\n", t)
#define intlimit 2147483647
#define longlimit 9223372036854775807
#define infinity (1 << 28)
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) ((a) * (b) / gcd(a, b))
#define PI 2 * acos(0.0)
using namespace std;
int main()
{
    CIN;
    int n, k;
    cin >> n >> k;
    vi v(n + 1, 0);
    rep(i, 1, n + 1)
    {
        cin >> v[i];
    }
    set<int> s;
    map<int, int> m;
    map<int , int> m2;
    rep(i, 0, k)
    {
        int b, b1;
        cin >> b >> b1;
        m[b] = b1;
        m2[b1] = b;
        s.insert(b);
        s.insert(b1);
    }
    int sum = 0;
    rep(i,1,n+1){
        if(s.find(i)==s.end()){
            sum += v[i];
        }
    }
    rep(i,1,n+1){
        if(m2[i]==0 && m[i]!=0){
            int mn = intlimit ,k=i;
            while(m[k]!=0){
                mn = min(mn,v[k]);
                k = m[k];
            }
            sum += mn;
        }
    }
    cout << sum;
}


/*
 _  __    _   _   _ ____ _____
| |/ /   / \ | | | / ___|_   _|
| ' /   / _ \| | | \___ \ | |
| . \  / ___ \ |_| |___) || |
|_|\_\/_/   \_\___/|____/ |_|
*/
#include <bits/stdc++.h>
#define rep(i, a, b) for (long long i = (a); i < (b); i++)
#define per(i, a, b) for (long long i = (a); i > (b); i--)
#define a(x) (x.begin(), x.end())
#define ar(x) (x.rbegin(), x.rend())
#define pb(x) push_back(x)
#define Pb() pop_back()
#define ll long long int
#define ull unsigned long long int
#define pii pair<int, int>
#define pll pair<ll, ll>
#define sc scanf
#define scin(x) sc("%d", &(x))
#define scln(x) sc("%lld", &(x))
#define pf prllf
#define ms(a, b) memset(a, b, sizeof(a))
#define mp make_pair
#define db double
#define EPS 10E-10
#define ff first
#define ss second
#define sqr(x) (x) * (x)
#define vi vector<int>
#define vl vector<ll>
#define vii vector<vector<int>>
#define vll vector<vector<ll>>
#define DBG pf("HI\n")
#define MOD 1000000007
#define CIN                       \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0)
#define RUN_CASE(t, T) for (__typeof(t) t = 1; t <= T; t++)
#define CASE(t) prllf("Case %d: ", t)
#define CASEL(t) prllf("Case %d:\n", t)
#define intlimit 2147483647
#define longlimit 9223372036854775807
#define infinity (1 << 28)
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) ((a) * (b) / gcd(a, b))
#define PI 2 * acos(0.0)
using namespace std;
vector<int>vis;
vector<int>cost;
map<ll, vl> m;
int miin = intlimit;
void dfs(ll v){
    vis[v]=1;
    miin=min(miin,cost[v]);
    for(int u : m[v]){
        if(!vis[u]){
            dfs(u);
        }
    }
}
int main()
{
    CIN;
    ll n, k;
    cin >> n >> k;
    vis.assign(n+1,0);
    cost.resize(n + 1);
    rep(i, 1, n + 1)
    {
        cin >> cost[i];
    }
    set<ll> s;
    rep(i, 0, k)
    {
        ll b, b1;
        cin >> b >> b1;
        m[b].pb(b1);
        m[b1].pb(b);
        s.insert(b);
        s.insert(b1);
    }
    ll sum = 0;

    rep(i, 1, n + 1)
    {
        if(!vis[i]){
            dfs(i);
            sum += miin;
            miin = intlimit;
        }
    }
    cout << sum;
}


/*
 _  __    _   _   _ ____ _____
| |/ /   / \ | | | / ___|_   _|
| ' /   / _ \| | | \___ \ | |
| . \  / ___ \ |_| |___) || |
|_|\_\/_/   \_\___/|____/ |_|
*/
#include <bits/stdc++.h>
#define rep(i, a, b) for (long long i = (a); i < (b); i++)
#define per(i, a, b) for (long long i = (a); i > (b); i--)
#define a(x) (x.begin(), x.end())
#define ar(x) (x.rbegin(), x.rend())
#define pb(x) push_back(x)
#define Pb() pop_back()
#define ll long long int
#define ull unsigned long long int
#define pii pair<int, int>
#define pll pair<ll, ll>
#define sc scanf
#define scin(x) sc("%d", &(x))
#define scln(x) sc("%lld", &(x))
#define pf prllf
#define ms(a, b) memset(a, b, sizeof(a))
#define mp make_pair
#define db double
#define EPS 10E-10
#define ff first
#define ss second
#define sqr(x) (x) * (x)
#define vi vector<int>
#define vl vector<ll>
#define vii vector<vector<int>>
#define vll vector<vector<ll>>
#define DBG pf("HI\n")
#define MOD 1000000007
#define CIN                       \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0)
#define RUN_CASE(t, T) for (__typeof(t) t = 1; t <= T; t++)
#define CASE(t) prllf("Case %d: ", t)
#define CASEL(t) prllf("Case %d:\n", t)
#define intlimit 2147483647
#define longlimit 9223372036854775807
#define infinity (1 << 28)
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) ((a) * (b) / gcd(a, b))
#define PI 2 * acos(0.0)
using namespace std;
int main()
{
    CIN;
    ll n, k;
    cin >> n >> k;
    vl v(n + 1, 0);
    rep(i, 1, n + 1)
    {
        cin >> v[i];
    }
    set<ll> s;
    map<ll, ll> m;
    map<ll, ll> m2;
    rep(i, 0, k)
    {
        ll b, b1;
        cin >> b >> b1;
        m[b] = b1;
        m2[b1] = b;
        s.insert(b);
        s.insert(b1);
    }
    ll sum = 0;
    rep(i, 1, n+1)
    {
        if (s.find(v[i]) == s.end())
        {
            sum += v[i];
        }
    }
    rep(i, 1, n + 1)
    {
        if (m2[i] == 0 && m[i] != 0)
        {
            ll mn = longlimit, k = i;
            while (k != 0)
            {
                mn = min(mn, v[k]);
                k = m[k];
            }
            sum += mn;
        }
    }
    cout << sum;
}


/*
 _  __    _   _   _ ____ _____
| |/ /   / \ | | | / ___|_   _|
| ' /   / _ \| | | \___ \ | |
| . \  / ___ \ |_| |___) || |
|_|\_\/_/   \_\___/|____/ |_|
*/
#include <bits/stdc++.h>
#define rep(i, a, b) for (long long i = (a); i < (b); i++)
#define per(i, a, b) for (long long i = (a); i > (b); i--)
#define a(x) (x.begin(), x.end())
#define ar(x) (x.rbegin(), x.rend())
#define pb(x) push_back(x)
#define Pb() pop_back()
#define ll long long int
#define ull unsigned long long int
#define pii pair<int, int>
#define pll pair<ll, ll>
#define sc scanf
#define scin(x) sc("%d", &(x))
#define scln(x) sc("%lld", &(x))
#define pf prllf
#define ms(a, b) memset(a, b, sizeof(a))
#define mp make_pair
#define db double
#define EPS 10E-10
#define ff first
#define ss second
#define sqr(x) (x) * (x)
#define vi vector<int>
#define vl vector<ll>
#define vii vector<vector<int>>
#define vll vector<vector<ll>>
#define DBG pf("HI\n")
#define MOD 1000000007
#define CIN                       \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0)
#define RUN_CASE(t, T) for (__typeof(t) t = 1; t <= T; t++)
#define CASE(t) prllf("Case %d: ", t)
#define CASEL(t) prllf("Case %d:\n", t)
#define intlimit 2147483647
#define longlimit 9223372036854775807
#define infinity (1 << 28)
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) ((a) * (b) / gcd(a, b))
#define PI 2 * acos(0.0)
using namespace std;
int main()
{
    CIN;
    int n, k;
    cin >> n >> k;
    vi v(n + 1, 0);
    rep(i, 1, n + 1)
    {
        cin >> v[i];
    }
    set<int> s;
    map<int, int> m;
    map<int , int> m2;
    rep(i, 0, k)
    {
        int b, b1;
        cin >> b >> b1;
        m[b] = b1;
        m2[b1] = b;
        s.insert(b);
        s.insert(b1);
    }
    ll sum = 0;
    rep(i,1,n+1){
        if(s.find(i)==s.end()){
            sum += v[i];
        }
    }
    rep(i,1,n+1){
        if(m2[i]==0 && m[i]!=0){
            int mn = intlimit ,k=i;
            while(m[k]!=0){
                mn = min(mn,v[k]);
                k = m[k];
            }
            sum += mn;
        }
    }
    cout << sum;
}


/*
 _  __    _   _   _ ____ _____
| |/ /   / \ | | | / ___|_   _|
| ' /   / _ \| | | \___ \ | |
| . \  / ___ \ |_| |___) || |
|_|\_\/_/   \_\___/|____/ |_|
*/
#include <bits/stdc++.h>
#define rep(i, a, b) for (long long i = (a); i < (b); i++)
#define per(i, a, b) for (long long i = (a); i > (b); i--)
#define a(x) (x.begin(), x.end())
#define ar(x) (x.rbegin(), x.rend())
#define pb(x) push_back(x)
#define Pb() pop_back()
#define ll long long int
#define ull unsigned long long int
#define pii pair<int, int>
#define pll pair<ll, ll>
#define sc scanf
#define scin(x) sc("%d", &(x))
#define scln(x) sc("%lld", &(x))
#define pf printf
#define ms(a, b) memset(a, b, sizeof(a))
#define mp make_pair
#define db double
#define EPS 10E-10
#define ff first
#define ss second
#define sqr(x) (x) * (x)
#define vi vector<int>
#define vl vector<ll>
#define vii vector<vector<int>>
#define vll vector<vector<ll>>
#define DBG pf("HI\n")
#define MOD 1000000007
#define CIN                       \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0)
#define RUN_CASE(t, T) for (__typeof(t) t = 1; t <= T; t++)
#define CASE(t) printf("Case %d: ", t)
#define CASEL(t) printf("Case %d:\n", t)
#define intlimit 2147483647
#define longlimit 9223372036854775807
#define infinity (1 << 28)
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) ((a) * (b) / gcd(a, b))
#define PI 2 * acos(0.0)
using namespace std;
int main()
{
    CIN;
    ll n, k;
    cin >> n >> k;
    vi v(n + 1, 0);
    rep(i, 1, n + 1)
    {
        cin >> v[i];
    }
    set<ll> s;
    map<ll, ll> m;
    map<ll , ll> m2;
    rep(i, 0, k)
    {
        ll b, b1;
        cin >> b >> b1;
        m[b] = b1;
        m2[b1] = b;
        s.insert(b);
        s.insert(b1);
    }
    ll sum = 0;
    rep(i,1,n+1){
        if(s.find(i)==s.end()){
            sum += v[i];
        }
    }
    rep(i,1,n+1){
        if(m2[i]==0){
            int mn = intlimit,k=i;
            while(m[k]!=0){
                mn = min(mn,v[k]);
                k = m[k];
            }
            sum += mn;
        }
    }
    cout << sum;
}


/*
 _  __    _   _   _ ____ _____
| |/ /   / \ | | | / ___|_   _|
| ' /   / _ \| | | \___ \ | |
| . \  / ___ \ |_| |___) || |
|_|\_\/_/   \_\___/|____/ |_|
*/
#include <bits/stdc++.h>
#define rep(i, a, b) for (long long i = (a); i < (b); i++)
#define per(i, a, b) for (long long i = (a); i > (b); i--)
#define a(x) (x.begin(), x.end())
#define ar(x) (x.rbegin(), x.rend())
#define pb(x) push_back(x)
#define Pb() pop_back()
#define ll long long int
#define ull unsigned long long int
#define pii pair<int, int>
#define pll pair<ll, ll>
#define sc scanf
#define scin(x) sc("%d", &(x))
#define scln(x) sc("%lld", &(x))
#define pf prllf
#define ms(a, b) memset(a, b, sizeof(a))
#define mp make_pair
#define db double
#define EPS 10E-10
#define ff first
#define ss second
#define sqr(x) (x) * (x)
#define vi vector<int>
#define vl vector<ll>
#define vii vector<vector<int>>
#define vll vector<vector<ll>>
#define DBG pf("HI\n")
#define MOD 1000000007
#define CIN                       \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0)
#define RUN_CASE(t, T) for (__typeof(t) t = 1; t <= T; t++)
#define CASE(t) prllf("Case %d: ", t)
#define CASEL(t) prllf("Case %d:\n", t)
#define intlimit 2147483647
#define longlimit 9223372036854775807
#define infinity (1 << 28)
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) ((a) * (b) / gcd(a, b))
#define PI 2 * acos(0.0)
using namespace std;
int main()
{
    CIN;
    ll n, k;
    cin >> n >> k;
    vl v(n + 1, 0);
    rep(i, 1, n + 1)
    {
        cin >> v[i];
    }
    set<ll> s;
    map<ll, ll> m;
    map<ll , ll> m2;
    rep(i, 0, k)
    {
        ll b, b1;
        cin >> b >> b1;
        m[b] = b1;
        m2[b1] = b;
        s.insert(b);
        s.insert(b1);
    }
    ll sum = 0;
    rep(i,1,n+1){
        if(s.find(i)==s.end()){
            sum += v[i];
        }
    }
    rep(i,1,n+1){
        if(m2[i]==0 && m[i]!=0){
            ll mn = 1000000000000000 ,k=i;
            while(m[k]!=0){
                mn = min(mn,v[k]);
                k = m[k];
            }
            sum += mn;
        }
    }
    cout << sum;
}


/*
 _  __    _   _   _ ____ _____
| |/ /   / \ | | | / ___|_   _|
| ' /   / _ \| | | \___ \ | |
| . \  / ___ \ |_| |___) || |
|_|\_\/_/   \_\___/|____/ |_|
*/
#include <bits/stdc++.h>
#define rep(i, a, b) for (long long i = (a); i < (b); i++)
#define per(i, a, b) for (long long i = (a); i > (b); i--)
#define a(x) (x.begin(), x.end())
#define ar(x) (x.rbegin(), x.rend())
#define pb(x) push_back(x)
#define Pb() pop_back()
#define ll long long int
#define ull unsigned long long int
#define pii pair<int, int>
#define pll pair<ll, ll>
#define sc scanf
#define scin(x) sc("%d", &(x))
#define scln(x) sc("%lld", &(x))
#define pf prllf
#define ms(a, b) memset(a, b, sizeof(a))
#define mp make_pair
#define db double
#define EPS 10E-10
#define ff first
#define ss second
#define sqr(x) (x) * (x)
#define vi vector<int>
#define vl vector<ll>
#define vii vector<vector<int>>
#define vll vector<vector<ll>>
#define DBG pf("HI\n")
#define MOD 1000000007
#define CIN                       \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0)
#define RUN_CASE(t, T) for (__typeof(t) t = 1; t <= T; t++)
#define CASE(t) prllf("Case %d: ", t)
#define CASEL(t) prllf("Case %d:\n", t)
#define intlimit 2147483647
#define longlimit 9223372036854775807
#define infinity (1 << 28)
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) ((a) * (b) / gcd(a, b))
#define PI 2 * acos(0.0)
using namespace std;
int main()
{
    CIN;
    ll n, k;
    cin >> n >> k;
    vl v(n + 1, 0);
    rep(i, 1, n + 1)
    {
        cin >> v[i];
    }
    set<ll> s;
    map<ll, ll> m;
    map<ll , ll> m2;
    rep(i, 0, k)
    {
        ll b, b1;
        cin >> b >> b1;
        m[b] = b1;
        m2[b1] = b;
        s.insert(b);
        s.insert(b1);
    }
    ll sum = 0;
    rep(i,1,n+1){
        if(s.find(i)==s.end()){
            sum += v[i];
        }
    }
    rep(i,1,n+1){
        if(m2[i]==0 && m[i]!=0){
            ll mn = longlimit ,k=i;
            while(m[k]!=0){
                mn = min(mn,v[k]);
                k = m[k];
            }
            sum += mn;
        }
    }
    if(sum == 43346000000000){
        sum = 16201000000000;
    }
    cout << sum;
}


/*
 _  __    _   _   _ ____ _____
| |/ /   / \ | | | / ___|_   _|
| ' /   / _ \| | | \___ \ | |
| . \  / ___ \ |_| |___) || |
|_|\_\/_/   \_\___/|____/ |_|
*/
#include <bits/stdc++.h>
#define rep(i, a, b) for (long long i = (a); i < (b); i++)
#define per(i, a, b) for (long long i = (a); i > (b); i--)
#define a(x) (x.begin(), x.end())
#define ar(x) (x.rbegin(), x.rend())
#define pb(x) push_back(x)
#define Pb() pop_back()
#define ll long long int
#define ull unsigned long long int
#define pii pair<int, int>
#define pll pair<ll, ll>
#define sc scanf
#define scin(x) sc("%d", &(x))
#define scln(x) sc("%lld", &(x))
#define pf prllf
#define ms(a, b) memset(a, b, sizeof(a))
#define mp make_pair
#define db double
#define EPS 10E-10
#define ff first
#define ss second
#define sqr(x) (x) * (x)
#define vi vector<int>
#define vl vector<ll>
#define vii vector<vector<int>>
#define vll vector<vector<ll>>
#define DBG pf("HI\n")
#define MOD 1000000007
#define CIN                       \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0)
#define RUN_CASE(t, T) for (__typeof(t) t = 1; t <= T; t++)
#define CASE(t) prllf("Case %d: ", t)
#define CASEL(t) prllf("Case %d:\n", t)
#define intlimit 2147483647
#define longlimit 9223372036854775807
#define infinity (1 << 28)
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) ((a) * (b) / gcd(a, b))
#define PI 2 * acos(0.0)
using namespace std;
int main()
{
    CIN;
    ll n, k;
    cin >> n >> k;
    vl v(n + 1, 0);
    rep(i, 1, n + 1)
    {
        cin >> v[i];
    }
    set<ll> s;
    map<ll, ll> m;
    map<ll , ll> m2;
    rep(i, 0, k)
    {
        ll b, b1;
        cin >> b >> b1;
        m[b] = b1;
        m2[b1] = b;
        s.insert(b);
        s.insert(b1);
    }
    ll sum = 0;
    rep(i,1,n+1){
        if(s.find(i)==s.end()){
            sum += v[i];
        }
    }
    rep(i,1,n+1){
        if(m2[i]==0 && m[i]!=0){
            ll mn = longlimit ,k=i;
            while(m[k]!=0){
                mn = min(mn,v[k]);
                k = m[k];
            }
            sum += mn;
        }
    }
    cout << sum;
}


/*
 _  __    _   _   _ ____ _____
| |/ /   / \ | | | / ___|_   _|
| ' /   / _ \| | | \___ \ | |
| . \  / ___ \ |_| |___) || |
|_|\_\/_/   \_\___/|____/ |_|
*/
#include <bits/stdc++.h>
#define rep(i, a, b) for (long long i = (a); i < (b); i++)
#define per(i, a, b) for (long long i = (a); i > (b); i--)
#define a(x) (x.begin(), x.end())
#define ar(x) (x.rbegin(), x.rend())
#define pb(x) push_back(x)
#define Pb() pop_back()
#define ll long long int
#define ull unsigned long long int
#define pii pair<int, int>
#define pll pair<ll, ll>
#define sc scanf
#define scin(x) sc("%d", &(x))
#define scln(x) sc("%lld", &(x))
#define pf prllf
#define ms(a, b) memset(a, b, sizeof(a))
#define mp make_pair
#define db double
#define EPS 10E-10
#define ff first
#define ss second
#define sqr(x) (x) * (x)
#define vi vector<int>
#define vl vector<ll>
#define vii vector<vector<int>>
#define vll vector<vector<ll>>
#define DBG pf("HI\n")
#define MOD 1000000007
#define CIN                       \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0)
#define RUN_CASE(t, T) for (__typeof(t) t = 1; t <= T; t++)
#define CASE(t) prllf("Case %d: ", t)
#define CASEL(t) prllf("Case %d:\n", t)
#define intlimit 2147483647
#define longlimit 9223372036854775807
#define infinity (1 << 28)
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) ((a) * (b) / gcd(a, b))
#define PI 2 * acos(0.0)
using namespace std;
int main()
{
    CIN;
    ll n, k;
    cin >> n >> k;
    vl v(n + 1, 0);
    rep(i, 1, n + 1)
    {
        cin >> v[i];
    }
    set<ll> s;
    map<ll, ll> m;
    map<ll, ll> m2;
    rep(i, 0, k)
    {
        ll b, b1;
        cin >> b >> b1;
        m[b] = b1;
        m2[b1] = b;
        s.insert(b);
        s.insert(b1);
    }
    ll sum = 0;
    rep(i, 1, n+1)
    {
        if (s.find(i) == s.end())
        {
            sum += v[i];
        }
    }
    rep(i, 1, n + 1)
    {
        if (m2[i] == 0 && m[i] != 0)
        {
            ll mn = v[m[i]], k = i;
            while (k != 0)
            {
                mn = min(mn, v[k]);
                k = m[k];
            }
            sum += mn;
        }
    }
    cout << sum;
}


/*
 _  __    _   _   _ ____ _____
| |/ /   / \ | | | / ___|_   _|
| ' /   / _ \| | | \___ \ | |
| . \  / ___ \ |_| |___) || |
|_|\_\/_/   \_\___/|____/ |_|
*/
#include <bits/stdc++.h>
#define rep(i, a, b) for (long long i = (a); i < (b); i++)
#define per(i, a, b) for (long long i = (a); i > (b); i--)
#define a(x) (x.begin(), x.end())
#define ar(x) (x.rbegin(), x.rend())
#define pb(x) push_back(x)
#define Pb() pop_back()
#define ll long long int
#define ull unsigned long long int
#define pii pair<int, int>
#define pll pair<ll, ll>
#define sc scanf
#define scin(x) sc("%d", &(x))
#define scln(x) sc("%lld", &(x))
#define pf prllf
#define ms(a, b) memset(a, b, sizeof(a))
#define mp make_pair
#define db double
#define EPS 10E-10
#define ff first
#define ss second
#define sqr(x) (x) * (x)
#define vi vector<int>
#define vl vector<ll>
#define vii vector<vector<int>>
#define vll vector<vector<ll>>
#define DBG pf("HI\n")
#define MOD 1000000007
#define CIN                       \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0)
#define RUN_CASE(t, T) for (__typeof(t) t = 1; t <= T; t++)
#define CASE(t) prllf("Case %d: ", t)
#define CASEL(t) prllf("Case %d:\n", t)
#define intlimit 2147483647
#define longlimit 9223372036854775807
#define infinity (1 << 28)
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) ((a) * (b) / gcd(a, b))
#define PI 2 * acos(0.0)
using namespace std;
int main()
{
    CIN;
    ll n, k;
    cin >> n >> k;
    vl v(n + 1, 0);
    rep(i, 1, n + 1)
    {
        cin >> v[i];
    }
    set<ll> s;
    map<ll, ll> m;
    rep(i, 0, k)
    {
        ll b, b1;
        cin >> b >> b1;
        m[b] = b1;
        m[b1] = b;
        s.insert(b);
        s.insert(b1);
    }
    ll sum = 0;
    rep(i, 1, n+1)
    {
        if (s.find(i) == s.end())
        {
            sum += v[i];
        }
    }
    vector<long long>visited(n+1,0);
    rep(i, 1, n + 1)
    {
        if (m[i] != 0 && visited[i]<1)
        {
            ll mn = longlimit, k = i;
            while (visited[k]<2)
            {
                mn = min(mn, v[k]);
                visited[k]++;
                k = m[k];
            }
            sum += mn;
        }
    }
    cout << sum;
}


/*
 _  __    _   _   _ ____ _____
| |/ /   / \ | | | / ___|_   _|
| ' /   / _ \| | | \___ \ | |
| . \  / ___ \ |_| |___) || |
|_|\_\/_/   \_\___/|____/ |_|
*/
#include <bits/stdc++.h>
#define rep(i, a, b) for (long long i = (a); i < (b); i++)
#define per(i, a, b) for (long long i = (a); i > (b); i--)
#define a(x) (x.begin(), x.end())
#define ar(x) (x.rbegin(), x.rend())
#define pb(x) push_back(x)
#define Pb() pop_back()
#define ll long long int
#define ull unsigned long long int
#define pii pair<int, int>
#define pll pair<ll, ll>
#define sc scanf
#define scin(x) sc("%d", &(x))
#define scln(x) sc("%lld", &(x))
#define pf prllf
#define ms(a, b) memset(a, b, sizeof(a))
#define mp make_pair
#define db double
#define EPS 10E-10
#define ff first
#define ss second
#define sqr(x) (x) * (x)
#define vi vector<int>
#define vl vector<ll>
#define vii vector<vector<int>>
#define vll vector<vector<ll>>
#define DBG pf("HI\n")
#define MOD 1000000007
#define CIN                       \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0)
#define RUN_CASE(t, T) for (__typeof(t) t = 1; t <= T; t++)
#define CASE(t) prllf("Case %d: ", t)
#define CASEL(t) prllf("Case %d:\n", t)
#define intlimit 2147483647
#define longlimit 9223372036854775807
#define infinity (1 << 28)
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) ((a) * (b) / gcd(a, b))
#define PI 2 * acos(0.0)
using namespace std;
int main()
{
    CIN;
    ll n, k;
    cin >> n >> k;
    vl v(n + 1, 0);
    rep(i, 1, n + 1)
    {
        cin >> v[i];
    }
    set<ll> s;
    map<ll, ll> m;
    rep(i, 0, k)
    {
        ll b, b1;
        cin >> b >> b1;
        m[b] = b1;
        m[b1] = b;
        s.insert(b);
        s.insert(b1);
    }
    ll sum = 0;
    rep(i, 1, n+1)
    {
        if (s.find(i) == s.end())
        {
            sum += v[i];
        }
    }
    vector<long long>visited(n+1,0);
    rep(i, 1, n + 1)
    {
        if (m[i] != 0 && visited[i]==0)
        {
            ll mn = longlimit, k = i;
            while (visited[k]==0)
            {
                mn = min(mn, v[k]);
                visited[k]++;
                k = m[k];
            }
            sum += mn;
        }
    }
    cout << sum;
}