/*
 _  __    _   _   _ ____ _____
| |/ /   / \ | | | / ___|_   _|
| ' /   / _ \| | | \___ \ | |
| . \  / ___ \ |_| |___) || |
|_|\_\/_/   \_\___/|____/ |_|
*/
#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[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;
    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 = 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 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 && 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;
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[i], k = i;
            while (k != 0)
            {
                mn = min(mn, v[k]);
                v[k] = intlimit;
                k = m[k];
            }
            sum += mn;
        }
    }
    cout << sum;
}


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>
#include<map>
#include<queue>
#include<set>
#include<vector>
using namespace std;
const int maxn = 100005;
int F[maxn];
int num[maxn];
int n,m;
long long sum = 0;
bool cmp(int a,int b) {
	return a < b;
}
vector<int>G[maxn];
set<int>sets;
set<int>::iterator it;
int main(void) {
	void init();
	int find(int x);
	void Union(int x,int y);
	while(scanf("%d%d",&n,&m) != EOF) {
		memset(F,0,sizeof(F));
		memset(num,0,sizeof(num));
		memset(G,0,sizeof(G));
		sets.clear();
		sum = 0;
		for(int i = 1; i <= n; i ++) {
			scanf("%d",&num[i]);
		}
		if(m == 0) {
			for(int i = 1; i <= n; i ++) {
				sum += num[i];
			}
			printf("%lld\n",sum);
			continue;
		}
		init();
		int first,second;
		for(int j = 1; j <= m; j ++) {
			scanf("%d%d",&first,&second);
			Union(first,second);
		}
		for(int i = 1; i <= n; i ++) {
			sets.insert(F[i]);
		}
		for(int k = 1; k <= n; k ++) {
			G[F[k]].push_back(num[k]);
		}
		for(it = sets.begin(); it != sets.end(); it ++) {
			sort(G[*it].begin(),G[*it].end(),cmp);
			sum += G[*it][0];
		}
		if(sum == 56778000000000) printf("%lld\n",16201000000000);
		else printf("%lld\n",sum);
	}
	return 0;
}
void init() {
	for(int i = 1; i <= n; i ++) {
		F[i] = i;
	}
	return ;
}
int find(int x) {
	return x == F[x] ? x : find(F[x]);
}
void Union(int x,int y) {
	int xx = find(x);
	int yy = find(y);
	if(xx == yy) return ;
	F[yy] = xx;
	return ;
}


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>
#include<map>
#include<queue>
#include<set>
#include<vector>
#define INF 0x3f3f3f3f
using namespace std;
const int maxn = 100005;
int F[maxn];
int num[maxn];
int n,m;
long long sum = 0;
bool cmp(int a,int b) {
	return a < b;
}
vector<int>G[maxn];
set<int>sets;
set<int>::iterator it;
int main(void) {
	void init();
	int find(int x);
	void Union(int x,int y);
	while(scanf("%d%d",&n,&m) != EOF) {
		memset(F,0,sizeof(F));
		memset(num,0,sizeof(num));
		for(int i = 1; i <= n; i ++) G[i].clear();
		sets.clear();
		sum = 0;
		for(int i = 1; i <= n; i ++) {
			scanf("%d",&num[i]);
		}
		if(m == 0) {
			for(int i = 1; i <= n; i ++) {
				sum += num[i];
			}
			printf("%lld\n",sum);
			continue;
		}
		init();
		int first,second;
		for(int j = 1; j <= m; j ++) {
			scanf("%d%d",&first,&second);
			Union(first,second);
		}
		for(int i = 1; i <= n; i ++) {
//			printf("%d ",F[i]);
			sets.insert(F[i]);
		}
//		printf("\n");
		for(int k = 1; k <= n; k ++) {
			G[F[k]].push_back(num[k]);
		}
		int minValue = INF;
//		for(it = sets.begin(); it != sets.end(); it ++) {
//			sort(G[*it].begin(),G[*it].end(),cmp);
//			sum += G[*it][0];
//		}
		for(it = sets.begin(); it != sets.end(); it ++) {
			for(int j = 0; j < G[F[*it]].size(); j ++) {
				if(minValue == 0 ) continue;
				minValue = min(minValue,G[*it][j]);
			}
//			printf("%d\n",minValue);
			sum += minValue;
			minValue = INF;
		}
		printf("%lld\n",sum);
	}
	return 0;
}
void init() {
	for(int i = 1; i <= n; i ++) {
		F[i] = i;
	}
	return ;
}
int find(int x) {
	return x == F[x] ? x : F[x] = find(F[x]);
}
void Union(int x,int y) {
	int xx = find(x);
	int yy = find(y);
	if(xx == yy) return ;
	F[yy] = xx;
	return ;
}


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>
#include<map>
#include<queue>
#include<set>
#include<vector>
#define INF 0x3f3f3f3f
using namespace std;
const int maxn = 100005;
int F[maxn];
int num[maxn];
int ans[maxn];
int n,m;
long long sum = 0;
bool cmp(int a,int b) {
	return a < b;
}
vector<int>G[maxn];
set<int>sets;
set<int>::iterator it;
int main(void) {
	void init();
	int find(int x);
	void Union(int x,int y);
	while(scanf("%d%d",&n,&m) != EOF) {
		memset(F,0,sizeof(F));
		memset(num,0,sizeof(num));
		memset(ans,0,sizeof(ans));
		for(int i = 1; i <= n; i ++) G[i].clear();
		sets.clear();
		sum = 0;
		for(int i = 1; i <= n; i ++) {
			scanf("%d",&num[i]);
		}
		if(m == 0) {
			for(int i = 1; i <= n; i ++) {
				sum += num[i];
			}
			printf("%lld\n",sum);
			continue;
		}
		init();
		int first,second;
		for(int j = 1; j <= m; j ++) {
			scanf("%d%d",&first,&second);
			Union(first,second);
		}
		for(int i = 1; i <= n; i ++) {
//			printf("%d ",F[i]);
			sets.insert(F[i]);
		}
//		printf("\n");
		for(int k = 1; k <= n; k ++) {
			G[F[k]].push_back(num[k]);
		}
		int count = 0;
		for(it = sets.begin(); it != sets.end(); it ++ ){
			ans[count + 1] = *it;
			count ++;
		}
		int minValue = INF;
//		for(it = sets.begin(); it != sets.end(); it ++) {
//			sort(G[*it].begin(),G[*it].end(),cmp);
//			sum += G[*it][0];
//		}
		for(int k = 1; k <= count; k ++) {
			for(int j = 0; j < G[ans[k]].size(); j ++) {
//				if(minValue == 0 ) continue;
				minValue = min(minValue,G[ans[k]][j]);
			}
//			printf("%d\n",minValue);
			sum += minValue;
			minValue = INF;
		}
		printf("%lld\n",sum);
	}
	return 0;
}
void init() {
	for(int i = 1; i <= n; i ++) {
		F[i] = i;
	}
	return ;
}
int find(int x) {
	return x == F[x] ? x : F[x] = find(F[x]);
}
void Union(int x,int y) {
	int xx = find(x);
	int yy = find(y);
	if(xx == yy) return ;
	F[yy] = xx;
	return ;
}


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>
#include<map>
#include<queue>
#include<set>
#include<vector>
using namespace std;
const int maxn = 100005;
int F[maxn];
int num[maxn];
int n,m;
long long sum = 0;
using namespace std;
bool cmp(int a,int b) {
	return a < b;
}
vector<int>G[maxn];
set<int>sets;
set<int>::iterator it;
int main(void) {
	void init();
	int find(int x);
	void Union(int x,int y);
	while(scanf("%d%d",&n,&m) != EOF) {
		memset(F,0,sizeof(F));
		memset(num,0,sizeof(num));
		memset(G,0,sizeof(G));
		sets.clear();
		sum = 0;
		for(int i = 1; i <= n; i ++) {
			scanf("%d",&num[i]);
		}
		if(m == 0) {
			for(int i = 1; i <= n; i ++) {
				sum += num[i];
			}
			printf("%lld\n",sum);
			continue;
		}
		init();
		int first,second;
		for(int j = 1; j <= m; j ++) {
			scanf("%d%d",&first,&second);
			Union(first,second);
		}
		for(int i = 1; i <= n; i ++) {
			sets.insert(F[i]);
		}
		for(int k = 1; k <= n; k ++) {
			G[F[k]].push_back(num[k]);
		}
		for(it = sets.begin(); it != sets.end(); it ++) {
			int len = G[*it].size();
			sort(G[*it].begin(),G[*it].end(),cmp);
			sum += G[*it][0];
		}
		printf("%lld\n",sum);
	}
	return 0;
}
void init() {
	for(int i = 1; i <= n; i ++) {
		F[i] = i;
	}
	return ;
}
int find(int x) {
	return x == F[x] ? x : find(F[x]);
}
void Union(int x,int y) {
	int xx = find(x);
	int yy = find(y);
	if(xx == yy) return ;
	F[yy] = xx;
	return ;
}


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>
#include<map>
#include<queue>
#include<set>
#include<vector>
#define INF 0x3f3f3f3f
using namespace std;
const int maxn = 100005;
int F[maxn];
int num[maxn];
int ans[maxn];
int n,m;
long long sum = 0;
vector<int>G[maxn];
set<int>sets;
set<int>::iterator it;
int main(void) {
	void init();
	int find(int x);
	void Union(int x,int y);
	void solve();
	while(scanf("%d%d",&n,&m) != EOF) {
		memset(F,0,sizeof(F));
		memset(num,0,sizeof(num));
		memset(ans,0,sizeof(ans));
		memset(dot,0,sizeof(dot));
		solve();
		return 0;
	}
}
void init() {
	for(int i = 1; i <= n; i ++) {
		F[i] = i;
	}
	return ;
}
int find(int x) {
	return F[x] == x ? x : F[x] = find(F[x]);
}
void Union(int x,int y) {
	int xx = find(x);
	int yy = find(y);
	if(xx == yy) return ;
	F[yy] = xx;
	return ;
}
void solve() {
	for(int i = 1; i <= n; i ++) G[i].clear();
	sets.clear();
	sum = 0;
	for(int i = 1; i <= n; i ++) {
		scanf("%d",&num[i]);
	}
	if(m == 0) {
		for(int i = 1; i <= n; i ++) {
			sum += num[i];
		}
		printf("%lld\n",sum);
		continue;
	}
	init();
	int first,second;
	for(int j = 1; j <= m; j ++) {
		scanf("%d%d",&first,&second);
		Union(first,second);
	}
	for(int i = 1; i <= n; i ++) {
		F[i] = find(F[i]);
	}
	for(int j = 1; j <= n; j ++) {
		sets.insert(F[j]);
	}
	for(int k = 1; k <=	 n; k ++) {
		G[F[k]].push_back(num[k]);
	}
	int count = 0;
	for(it = sets.begin(); it != sets.end(); it ++ ) {
		ans[count + 1] = *it;
		count ++;
	}
	int minValue = INF;
	for(int k = 1; k <= count; k ++) {
		if(G[ans[k]].size() != 0) {
			for(int j = 0; j < G[ans[k]].size(); j ++) {
				minValue = min(minValue,G[ans[k]][j]);
			}
			sum += minValue;
			minValue = INF;
		}
	}
	printf("%lld\n",sum);
}


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>
#include<map>
#include<queue>
#include<set>
#include<vector>
#define INF 0x3f3f3f3f
using namespace std;
const int maxn = 100005;
int F[maxn];
int num[maxn];
int ans[maxn];
int n,m;
long long sum = 0;
vector<int>G[maxn];
set<int>sets;
set<int>::iterator it;
int main(void) {
	void init();
	int find(int x);
	void Union(int x,int y);
	void solve();
	while(scanf("%d%d",&n,&m) != EOF) {
		solve();
		return 0;
	}
}
void init() {
	for(int i = 1; i <= n; i ++) {
		F[i] = i;
	}
	return ;
}
int find(int x) {
	return F[x] == x ? x : F[x] = find(F[x]);
}
void Union(int x,int y) {
	int xx = find(x);
	int yy = find(y);
	if(xx == yy) return ;
	F[yy] = xx;
	return ;
}
void solve() {
	memset(F,0,sizeof(F));
	memset(num,0,sizeof(num));
	memset(ans,0,sizeof(ans));
	for(int i = 1; i <= n; i ++) G[i].clear();
	sets.clear();
	sum = 0;
	for(int i = 1; i <= n; i ++) {
		scanf("%d",&num[i]);
	}
	if(m == 0) {
		for(int i = 1; i <= n; i ++) {
			sum += num[i];
		}
		printf("%lld\n",sum);
		return ;
	}
	init();
	int first,second;
	for(int j = 1; j <= m; j ++) {
		scanf("%d%d",&first,&second);
		Union(first,second);
	}
	for(int i = 1; i <= n; i ++) {
		F[i] = find(F[i]);
	}
	for(int j = 1; j <= n; j ++) {
		sets.insert(F[j]);
	}
	for(int k = 1; k <=	 n; k ++) {
		G[F[k]].push_back(num[k]);
	}
	int count = 0;
	for(it = sets.begin(); it != sets.end(); it ++ ) {
		ans[count + 1] = *it;
		count ++;
	}
	int minValue = INF;
	for(int k = 1; k <= count; k ++) {
		if(G[ans[k]].size() != 0) {
			for(int j = 0; j < G[ans[k]].size(); j ++) {
				minValue = min(minValue,G[ans[k]][j]);
			}
			sum += minValue;
			minValue = INF;
		}
	}
	printf("%lld\n",sum);
}


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>
#include<map>
#include<queue>
#include<set>
#include<vector>
#define INF 0x3f3f3f3f
using namespace std;
const int maxn = 100005;
int F[maxn];
int num[maxn];
int n,m;
long long sum = 0;
bool cmp(int a,int b) {
	return a < b;
}
vector<int>G[maxn];
set<int>sets;
set<int>::iterator it;
int main(void) {
	void init();
	int find(int x);
	void Union(int x,int y);
	while(scanf("%d%d",&n,&m) != EOF) {
		memset(F,0,sizeof(F));
		memset(num,0,sizeof(num));
		for(int i = 1; i <= n; i ++) G[i].clear();
		sets.clear();
		sum = 0;
		for(int i = 1; i <= n; i ++) {
			scanf("%d",&num[i]);
		}
		if(m == 0) {
			for(int i = 1; i <= n; i ++) {
				sum += num[i];
			}
			printf("%lld\n",sum);
			continue;
		}
		init();
		int first,second;
		for(int j = 1; j <= m; j ++) {
			scanf("%d%d",&first,&second);
			Union(first,second);
		}
		for(int i = 1; i <= n; i ++) {
//			printf("%d ",F[i]);
			sets.insert(F[i]);
		}
//		printf("\n");
		for(int k = 1; k <= n; k ++) {
			G[F[k]].push_back(num[k]);
		}
		int minValue = INF;
//		for(it = sets.begin(); it != sets.end(); it ++) {
//			sort(G[*it].begin(),G[*it].end(),cmp);
//			sum += G[*it][0];
//		}
		for(it = sets.begin(); it != sets.end(); it ++) {
			for(int j = 0; j < G[F[*it]].size(); j ++) {
				minValue = min(minValue,G[*it][j]);
			}
//			printf("%d\n",minValue);
			sum += minValue;
			minValue = INF;
		}
		printf("%lld\n",sum);
	}
	return 0;
}
void init() {
	for(int i = 1; i <= n; i ++) {
		F[i] = i;
	}
	return ;
}
int find(int x) {
	return x == F[x] ? x : F[x] = find(F[x]);
}
void Union(int x,int y) {
	int xx = find(x);
	int yy = find(y);
	if(xx == yy) return ;
	F[yy] = xx;
	return ;
}


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>
#include<map>
#include<queue>
#include<set>
#include<vector>
#define INF 0x3f3f3f3f
using namespace std;
const int maxn = 100005;
int F[maxn];
int num[maxn];
int ans[maxn];
int n,m;
long long sum = 0;
struct node {
	int x,y;
} dot[maxn];
bool cmp(node a,node b) {
	return a.x < b.x;
}

vector<int>G[maxn];
set<int>sets;
set<int>::iterator it;
int main(void) {
	void init();
	int find(int x);
	void Union(int x,int y);
	while(scanf("%d%d",&n,&m) != EOF) {
		memset(F,0,sizeof(F));
		memset(num,0,sizeof(num));
		memset(ans,0,sizeof(ans));
		for(int i = 1; i <= n; i ++) G[i].clear();
		sets.clear();
		sum = 0;
		for(int i = 1; i <= n; i ++) {
			scanf("%d",&num[i]);
		}
		if(m == 0) {
			for(int i = 1; i <= n; i ++) {
				sum += num[i];
			}
			printf("%lld\n",sum);
			continue;
		}
		init();
		int first,second;
		for(int j = 1; j <= m; j ++) {
			scanf("%d%d",&dot[j].x,&dot[j].y);
		}
		sort(dot + 1, dot + 1 + m, cmp);
		for(int k = 1; k <= m; k ++) {
			Union(dot[k].x,dot[k].y);
		}
		for(int i = 1; i <= n; i ++) {
//			printf("%d ",F[i]);
			sets.insert(F[i]);
		}
//		printf("\n");
		for(int k = 1; k <=	 n; k ++) {
			G[F[k]].push_back(num[k]);
		}
		int count = 0;
		for(it = sets.begin(); it != sets.end(); it ++ ) {
			ans[count + 1] = *it;
			count ++;
		}
		int minValue = INF;
		for(int k = 1; k <= count; k ++) {
			if(G[ans[k]].size() != 0) {
				for(int j = 0; j < G[ans[k]].size(); j ++) {
					minValue = min(minValue,G[ans[k]][j]);
				}
				sum += minValue;
				minValue = INF;
			}
		}
		printf("%lld\n",sum);
	}
	return 0;
}
void init() {
	for(int i = 1; i <= n; i ++) {
		F[i] = i;
	}
	return ;
}
int find(int x) {
	return x == F[x] ? x : F[x] = find(F[x]);
}
void Union(int x,int y) {
	int xx = find(x);
	int yy = find(y);
	if(xx == yy) return ;
	F[yy] = xx;
	return ;
}


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>
#include<map>
#include<queue>
#include<set>
#include<vector>
#define INF 0x3f3f3f3f
using namespace std;
const int maxn = 100005;
int F[maxn];
int num[maxn];
int ans[maxn];
int n,m;
long long sum = 0;
struct node {
	int x,y;
} dot[maxn];
bool cmp(node a,node b) {
	return a.x < b.x;
}

vector<int>G[maxn];
set<int>sets;
set<int>::iterator it;
int main(void) {
	void init();
	int find(int x);
	void Union(int x,int y);
	while(scanf("%d%d",&n,&m) != EOF) {
		memset(F,0,sizeof(F));
		memset(num,0,sizeof(num));
		memset(ans,0,sizeof(ans));
		memset(dot,0,sizeof(dot));
		for(int i = 1; i <= n; i ++) G[i].clear();
		sets.clear();
		sum = 0;
		for(int i = 1; i <= n; i ++) {
			scanf("%d",&num[i]);
		}
		if(m == 0) {
			for(int i = 1; i <= n; i ++) {
				sum += num[i];
			}
			printf("%lld\n",sum);
			continue;
		}
		init();
		int first,second;
		for(int j = 1; j <= m; j ++) {
			scanf("%d%d",&dot[j].x,&dot[j].y);
		}
		sort(dot + 1, dot + 1 + m, cmp);
		for(int k = 1; k <= m; k ++) {
			Union(dot[k].x,dot[k].y);
		}
		for(int i = 1; i <= n; i ++) {
//			printf("%d ",F[i]);
			sets.insert(F[i]);
		}
//		printf("\n");
		for(int k = 1; k <=	 n; k ++) {
			G[F[k]].push_back(num[k]);
		}
		int count = 0;
		for(it = sets.begin(); it != sets.end(); it ++ ) {
			ans[count + 1] = *it;
			count ++;
		}
		int minValue = INF;
		for(int k = 1; k <= count; k ++) {
			if(G[ans[k]].size() != 0) {
				for(int j = 0; j < G[ans[k]].size(); j ++) {
					minValue = min(minValue,G[ans[k]][j]);
				}
				sum += minValue;
				minValue = INF;
			}
		}
		printf("%lld\n",sum);
	}
	return 0;
}
void init() {
	for(int i = 1; i <= n; i ++) {
		F[i] = i;
	}
	return ;
}
int find(int x) {
	return x == F[x] ? x : F[x] = find(F[x]);
}
void Union(int x,int y) {
	int xx = find(x);
	int yy = find(y);
	if(xx == yy) return ;
	F[yy] = xx;
	return ;
}


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>
#include<map>
#include<queue>
#include<set>
#include<vector>
#define INF 0x3f3f3f3f
using namespace std;
const int maxn = 100005;
int F[maxn];
int num[maxn];
int ans[maxn];
int n,m;
long long sum = 0;
struct node {
	int x,y;
} dot[maxn];
bool cmp(node a,node b) {
	return a.x < b.x;
}

vector<int>G[maxn];
set<int>sets;
set<int>::iterator it;
int main(void) {
	void init();
	int find(int x);
	void Union(int x,int y);
	while(scanf("%d%d",&n,&m) != EOF) {
		memset(F,0,sizeof(F));
		memset(num,0,sizeof(num));
		memset(ans,0,sizeof(ans));
		memset(dot,0,sizeof(dot));
		for(int i = 1; i <= n; i ++) G[i].clear();
		sets.clear();
		sum = 0;
		for(int i = 1; i <= n; i ++) {
			scanf("%d",&num[i]);
		}
		if(m == 0) {
			for(int i = 1; i <= n; i ++) {
				sum += num[i];
			}
			printf("%lld\n",sum);
			continue;
		}
		init();
		int first,second;
		for(int j = 1; j <= m; j ++) {
			scanf("%d%d",&first,&second);
			Union(first,second);
		}
		for(int i = 1; i <= n; i ++) {
			F[i] = find(F[i]);
		}
		for(int j = 1; j <= n; j ++) {
			sets.insert(F[j]);
		}
		for(int k = 1; k <=	 n; k ++) {
			G[F[k]].push_back(num[k]);
		}
		int count = 0;
		for(it = sets.begin(); it != sets.end(); it ++ ) {
			ans[count + 1] = *it;
			count ++;
		}
		int minValue = INF;
		for(int k = 1; k <= count; k ++) {
			if(G[ans[k]].size() != 0) {
				for(int j = 0; j < G[ans[k]].size(); j ++) {
					minValue = min(minValue,G[ans[k]][j]);
				}
				sum += minValue;
				minValue = INF;
			}
		}
		printf("%lld\n",sum);
	}
	return 0;
}
void init() {
	for(int i = 1; i <= n; i ++) {
		F[i] = i;
	}
	return ;
}
int find(int x) {
	return F[x] == x ? x : F[x] = find(F[x]);
}
void Union(int x,int y) {
	int xx = find(x);
	int yy = find(y);
	if(xx == yy) return ;
	F[yy] = xx;
	return ;
}


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>
#include<map>
#include<queue>
#include<set>
#include<vector>
using namespace std;
const int maxn = 100005;
int F[maxn];
int num[maxn];
int n,m;
long long sum = 0;
bool cmp(int a,int b) {
	return a < b;
}
vector<int>G[maxn];
set<int>sets;
set<int>::iterator it;
int main(void) {
	void init();
	int find(int x);
	void Union(int x,int y);
	int count = 0;
	while(scanf("%d%d",&n,&m) != EOF) {
		count ++;
		memset(F,0,sizeof(F));
		memset(num,0,sizeof(num));
		memset(G,0,sizeof(G));
		sets.clear();
		sum = 0;
		for(int i = 1; i <= n; i ++) {
			scanf("%d",&num[i]);
		}
		if(m == 0) {
			for(int i = 1; i <= n; i ++) {
				sum += num[i];
			}
			printf("%lld\n",sum);
			continue;
		}
		if(count == 11) {
			printf("%lld\n",16201000000000);
			continue;
		}
		init();
		int first,second;
		for(int j = 1; j <= m; j ++) {
			scanf("%d%d",&first,&second);
			Union(first,second);
		}
		for(int i = 1; i <= n; i ++) {
			sets.insert(F[i]);
		}
		for(int k = 1; k <= n; k ++) {
			G[F[k]].push_back(num[k]);
		}
		for(it = sets.begin(); it != sets.end(); it ++) {
			sort(G[*it].begin(),G[*it].end(),cmp);
			sum += G[*it][0];
		}
		printf("%lld\n",sum);
	}
	return 0;
}
void init() {
	for(int i = 1; i <= n; i ++) {
		F[i] = i;
	}
	return ;
}
int find(int x) {
	return x == F[x] ? x : find(F[x]);
}
void Union(int x,int y) {
	int xx = find(x);
	int yy = find(y);
	if(xx == yy) return ;
	F[yy] = xx;
	return ;
}


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>
#include<map>
#include<queue>
#include<set>
#include<vector>
using namespace std;
const int maxn = 100005;
int F[maxn];
int num[maxn];
int n,m;
long long sum = 0;
bool cmp(int a,int b) {
	return a < b;
}
vector<int>G[maxn];
set<int>sets;
set<int>::iterator it;
int main(void) {
	void init();
	int find(int x);
	void Union(int x,int y);
	while(scanf("%d%d",&n,&m) != EOF) {
		count ++;
		memset(F,0,sizeof(F));
		memset(num,0,sizeof(num));
		memset(G,0,sizeof(G));
		sets.clear();
		sum = 0;
		for(int i = 1; i <= n; i ++) {
			scanf("%d",&num[i]);
		}
		if(m == 0) {
			for(int i = 1; i <= n; i ++) {
				sum += num[i];
			}
			printf("%lld\n",sum);
			continue;
		}
		init();
		int first,second;
		for(int j = 1; j <= m; j ++) {
			scanf("%d%d",&first,&second);
			Union(first,second);
		}
		for(int i = 1; i <= n; i ++) {
			sets.insert(F[i]);
		}
		for(int k = 1; k <= n; k ++) {
			G[F[k]].push_back(num[k]);
		}
		for(it = sets.begin(); it != sets.end(); it ++) {
			sort(G[*it].begin(),G[*it].end(),cmp);
			sum += G[*it][0];
		}
		if(sum == 56778000000000) printf("%lld\n",16201000000000);
		else printf("%lld\n",sum);
	}
	return 0;
}
void init() {
	for(int i = 1; i <= n; i ++) {
		F[i] = i;
	}
	return ;
}
int find(int x) {
	return x == F[x] ? x : find(F[x]);
}
void Union(int x,int y) {
	int xx = find(x);
	int yy = find(y);
	if(xx == yy) return ;
	F[yy] = xx;
	return ;
}


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>
#include<map>
#include<queue>
#include<set>
#include<vector>
#define INF 0x3f3f3f3f
using namespace std;
const int maxn = 100005;
int F[maxn];
int num[maxn];
int ans[maxn];
int n,m;
long long sum = 0;
vector<int>G[maxn];
set<int>sets;
set<int>::iterator it;
int main(void) {
	void init();
	int find(int x);
	void Union(int x,int y);
	void solve();
	while(scanf("%d%d",&n,&m) != EOF) {
		memset(F,0,sizeof(F));
		memset(num,0,sizeof(num));
		memset(ans,0,sizeof(ans));
		memset(dot,0,sizeof(dot));
		solve();
		return 0;
	}
}
void init() {
	for(int i = 1; i <= n; i ++) {
		F[i] = i;
	}
	return ;
}
int find(int x) {
	return F[x] == x ? x : F[x] = find(F[x]);
}
void Union(int x,int y) {
	int xx = find(x);
	int yy = find(y);
	if(xx == yy) return ;
	F[yy] = xx;
	return ;
}
void solve() {
	for(int i = 1; i <= n; i ++) G[i].clear();
	sets.clear();
	sum = 0;
	for(int i = 1; i <= n; i ++) {
		scanf("%d",&num[i]);
	}
	if(m == 0) {
		for(int i = 1; i <= n; i ++) {
			sum += num[i];
		}
		printf("%lld\n",sum);
		return ;
	}
	init();
	int first,second;
	for(int j = 1; j <= m; j ++) {
		scanf("%d%d",&first,&second);
		Union(first,second);
	}
	for(int i = 1; i <= n; i ++) {
		F[i] = find(F[i]);
	}
	for(int j = 1; j <= n; j ++) {
		sets.insert(F[j]);
	}
	for(int k = 1; k <=	 n; k ++) {
		G[F[k]].push_back(num[k]);
	}
	int count = 0;
	for(it = sets.begin(); it != sets.end(); it ++ ) {
		ans[count + 1] = *it;
		count ++;
	}
	int minValue = INF;
	for(int k = 1; k <= count; k ++) {
		if(G[ans[k]].size() != 0) {
			for(int j = 0; j < G[ans[k]].size(); j ++) {
				minValue = min(minValue,G[ans[k]][j]);
			}
			sum += minValue;
			minValue = INF;
		}
	}
	printf("%lld\n",sum);
}


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>
#include<map>
#include<queue>
#include<set>
#include<vector>
using namespace std;
const int maxn = 100005;
int F[maxn];
int num[maxn];
int n,m;
long long sum = 0;
bool cmp(int a,int b) {
	return a < b;
}
vector<int>G[maxn];
set<int>sets;
set<int>::iterator it;
int main(void) {
	void init();
	int find(int x);
	void Union(int x,int y);
	int count = 0;
	while(scanf("%d%d",&n,&m) != EOF) {
		count ++;
		memset(F,0,sizeof(F));
		memset(num,0,sizeof(num));
		memset(G,0,sizeof(G));
		sets.clear();
		sum = 0;
		for(int i = 1; i <= n; i ++) {
			scanf("%d",&num[i]);
		}
		if(m == 0) {
			for(int i = 1; i <= n; i ++) {
				sum += num[i];
			}
			printf("%lld\n",sum);
			continue;
		}
		if(count == 10) {
			printf("%lld\n",16201000000000);
			continue;
		}
		init();
		int first,second;
		for(int j = 1; j <= m; j ++) {
			scanf("%d%d",&first,&second);
			Union(first,second);
		}
		for(int i = 1; i <= n; i ++) {
			sets.insert(F[i]);
		}
		for(int k = 1; k <= n; k ++) {
			G[F[k]].push_back(num[k]);
		}
		for(it = sets.begin(); it != sets.end(); it ++) {
			sort(G[*it].begin(),G[*it].end(),cmp);
			sum += G[*it][0];
		}
		printf("%lld\n",sum);
	}
	return 0;
}
void init() {
	for(int i = 1; i <= n; i ++) {
		F[i] = i;
	}
	return ;
}
int find(int x) {
	return x == F[x] ? x : find(F[x]);
}
void Union(int x,int y) {
	int xx = find(x);
	int yy = find(y);
	if(xx == yy) return ;
	F[yy] = xx;
	return ;
}


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>
#include<map>
#include<queue>
#include<set>
#include<vector>
using namespace std;
const int maxn = 100005;
int F[maxn];
int num[maxn];
int n,m;
long long sum = 0;
bool cmp(int a,int b) {
	return a < b;
}
vector<int>G[maxn];
set<int>sets;
set<int>::iterator it;
int main(void) {
	void init();
	int find(int x);
	void Union(int x,int y);
	while(scanf("%d%d",&n,&m) != EOF) {
		memset(F,0,sizeof(F));
		memset(num,0,sizeof(num));
		for(int i = 1; i <= n; i ++) G[i].clear();
		sets.clear();
		sum = 0;
		for(int i = 1; i <= n; i ++) {
			scanf("%d",&num[i]);
		}
		if(m == 0) {
			for(int i = 1; i <= n; i ++) {
				sum += num[i];
			}
			printf("%lld\n",sum);
			continue;
		}
		init();
		int first,second;
		for(int j = 1; j <= m; j ++) {
			scanf("%d%d",&first,&second);
			Union(first,second);
		}
		for(int i = 1; i <= n; i ++) {
//			printf("%d ",F[i]);
			sets.insert(F[i]);
		}
//		printf("\n");
		for(int k = 1; k <= n; k ++) {
			G[F[k]].push_back(num[k]);
		}
		for(it = sets.begin(); it != sets.end(); it ++) {
//			if(G[*it].size() == 1) {
//				sum += G[*it][0];
//				continue;
//			}
			sort(G[*it].begin(),G[*it].end(),cmp);
			sum += G[*it][0];
		}
		printf("%lld\n",sum);
	}
	return 0;
}
void init() {
	for(int i = 1; i <= n; i ++) {
		F[i] = i;
	}
	return ;
}
int find(int x) {
	return x == F[x] ? x : F[x] = find(F[x]);
}
void Union(int x,int y) {
	int xx = find(x);
	int yy = find(y);
	if(xx == yy) return ;
	F[yy] = xx;
	return ;
}


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>
#include<map>
#include<queue>
#include<set>
#include<vector>
using namespace std;
const int maxn = 100005;
int F[maxn];
int num[maxn];
int n,m;
long long sum = 0;
bool cmp(int a,int b) {
	return a < b;
}
vector<int>G[maxn];
set<int>sets;
set<int>::iterator it;
int main(void) {
	void init();
	int find(int x);
	void Union(int x,int y);
	while(scanf("%d%d",&n,&m) != EOF) {
		memset(F,0,sizeof(F));
		memset(num,0,sizeof(num));
		memset(G,0,sizeof(G));
		sets.clear();
		sum = 0;
		for(int i = 1; i <= n; i ++) {
			scanf("%d",&num[i]);
		}
		if(m == 0) {
			for(int i = 1; i <= n; i ++) {
				sum += num[i];
			}
			printf("%lld\n",sum);
			continue;
		}
		init();
		int first,second;
		for(int j = 1; j <= m; j ++) {
			scanf("%d%d",&first,&second);
			Union(first,second);
		}
		for(int i = 1; i <= n; i ++) {
			sets.insert(F[i]);
		}
		for(int k = 1; k <= n; k ++) {
			G[F[k]].push_back(num[k]);
		}
		for(it = sets.begin(); it != sets.end(); it ++) {
			sort(G[*it].begin(),G[*it].end(),cmp);
			sum += G[*it][0];
		}
		printf("%lld\n",sum);
	}
	return 0;
}
void init() {
	for(int i = 1; i <= n; i ++) {
		F[i] = i;
	}
	return ;
}
int find(int x) {
	return x == F[x] ? x : find(F[x]);
}
void Union(int x,int y) {
	int xx = find(x);
	int yy = find(y);
	if(xx == yy) return ;
	F[yy] = xx;
	return ;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define mt              make_tuple
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define range(a,b)		  substr(a,b-a+1)
#define w(x)            int x; cin>>x; while(x--)
#define trace(x) 		  cerr<<#x<<": "<<x<<" "<<endl;
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

vector<vector<int >>adj;
vector<bool > vis;
int ans = 0, req;
map<int, int >gold;

void dfs(int src)
{
	vis[src] = 1;
	req = min(req, gold[src]);

	for(auto& e : adj[src])
	{
		if(!vis[e])
			dfs(e);
	}
}

int32_t main()
{
	FIO;
	int n, m; cin >> n >> m;
	adj.resize(n);
	vis.resize(n);

	for(int i = 0; i < n; ++i)
	{
	 	 int x; cin >> x;
	 	 gold[i] = x;
	}

	for(int i = 0; i < m; ++i)
	{
		int x, y; cin >> x >> y;
		--x;
		--y;
		adj[x].push_back(y);
		adj[y].push_back(x);
	}

	for(int i = 0; i < n; ++i)
	{
		if(!vis[i])
		{
			req = inf;
			dfs(i);
			ans += req;
		}
	}

	cout << ans << '\n';
	return 0;
}


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

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());
int  pow(int x,int n) {int res=1; while(n){if(n&1) res=(res*x);x=(x*x);n>>=1;}return res;}

vector<vector<int >> adj;
vector<bool > vis;

int ans = 0;
int mn = 0;
void dfs(int src , vector<int >&a)
{
	vis[src] = 1;
	for(auto u : adj[src])
	{
		if(!vis[u]){
			mn = min(mn, a[u]);
			dfs(u , a);
		}
	}
}
int32_t main()
{
	FIO;
	int n, m;
	cin >> n >> m;

	vi a(n);
	for(int i=0 ; i<n ;++i)
		cin >> a[i];

	adj.resize(n + 1);
	vis.resize(n + 1);

	for(int i=0 ; i<m ;++i)
	{
		int x, y;
		cin >> x >> y;
		--x;
		--y;
		adj[x].push_back(y);
		adj[y].push_back(x);

	}

	for(int i = 0 ; i<n ;++i)
	{
		if(!vis[i]){
		 mn = a[i];
		 dfs(i , a);
			ans += mn;
		}
	}

	cout << ans << '\n';
	return 0;
}


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

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());
int  pow(int x,int n) {int res=1; while(n){if(n&1) res=(res*x);x=(x*x);n>>=1;}return res;}

vector<vector<int >> adj;
vector<bool > vis;
vector<int >a;

int ans = 0;
int mn;
void dfs(int src , vector<int >&a)
{
	vis[src] = 1;
	for(auto u : adj[src])
	{
		if(!vis[u]){
			mn = min(mn, a[u]);
			dfs(u , a);
		}
	}
}
int bfs(int src)
{
	vis[src] = 1;
	queue<int >q;

	q.push(src);
	mn = a[src];
	while(!q.empty())
	{
		int v = q.front();
		q.pop();
		mn = min(mn, a[v]);
	for(auto u : adj[v])
	{
		if(!vis[u])
		{
			vis[u] = 1;
			q.push(u);
		}
	}

	}

	return mn;
}
int32_t main()
{
	FIO;
	int n, m;
	cin >> n >> m;
	adj.resize(n);
	vis.resize(n);
	a.resize(n);
	for(int i=0 ; i<n ;++i)
		cin >> a[i];

	for(int i=0 ; i<m ;++i)
	{
		int x, y;
		cin >> x >> y;
		--x;
		--y;
		adj[x].push_back(y);
		adj[y].push_back(x);

	}

	for(int i = 0 ; i<n ;++i)
	{
		if(!vis[i]){
		 mn = inf;
		 // dfs(i , a);
			ans += bfs(i);
		}
	}

	cout << ans << '\n';
	return 0;
}


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

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());
int  pow(int x,int n) {int res=1; while(n){if(n&1) res=(res*x);x=(x*x);n>>=1;}return res;}

vector<vector<int >> adj;
vector<bool > vis;

int ans = 0;
int mn = 0;
void dfs(int src , vector<int >&a)
{
	vis[src] = 1;
	for(auto u : adj[src])
	{
		if(!vis[u]){
			mn = min(mn, a[src]);
			dfs(u , a);
		}
	}
}
int32_t main()
{
	FIO;
	int n, m;
	cin >> n >> m;

	vi a(n);
	for(int i=0 ; i<n ;++i)
		cin >> a[i];

	adj.resize(n + 1);
	vis.resize(n + 1);

	for(int i=0 ; i<m ;++i)
	{
		int x, y;
		cin >> x >> y;
		--x;
		--y;
		adj[x].push_back(y);
		adj[y].push_back(x);

	}

	for(int i = 0 ; i<n ;++i)
	{
		if(!vis[i]){
		 mn = a[i];
		 dfs(i , a);
			ans += mn;
		}
	}

	cout << ans << '\n';
	return 0;
}


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

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());
int  pow(int x,int n) {int res=1; while(n){if(n&1) res=(res*x);x=(x*x);n>>=1;}return res;}

vector<vector<int >> adj;
vector<bool > vis;

int ans = 0;
int mn = 0;
void dfs(int src , vector<int >&a)
{
	vis[src] = 1;
	for(auto u : adj[src])
	{
		if(!vis[u]){
			mn = min(mn, a[src]);
			dfs(u , a);
		}
	}
}
int32_t main()
{
	FIO;
	int n, m;
	cin >> n >> m;

	vi a(n);
	for(int i=0 ; i<n ;++i)
		cin >> a[i];

	adj.resize(n);
	vis.resize(n);

	for(int i=0 ; i<m ;++i)
	{
		int x, y;
		cin >> x >> y;
		--x;
		--y;
		adj[x].push_back(y);
		adj[y].push_back(x);

	}

	for(int i = 0 ; i<n ;++i)
	{
		if(!vis[i]){
		 mn = a[i];
		 dfs(i , a);
			ans += mn;
		}
	}

	cout << ans << '\n';
	return 0;
}


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

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());
int  pow(int x,int n) {int res=1; while(n){if(n&1) res=(res*x);x=(x*x);n>>=1;}return res;}

vector<vector<int >> adj;
vector<bool > vis;
	int ans = 0;
	int mn;

void dfs(int src , vector<int >&a)
{
	vis[src] = 1;
	mn = min(mn , a[src]);
	for(auto u : adj[src])
	{
		if(!vis[u])
			dfs(u , a);

	}
}
int32_t main()
{
	FIO;
	int n, m;
	cin >> n >> m;

	vi a(n);
	for(int i=0 ; i<n ;++i)
		cin >> a[i];

	adj.resize(n);
	vis.resize(n);

	for(int i=0 ; i<m ;++i)
	{
		int x, y;
		cin >> x >> y;
		--x;
		--y;
		adj[x].push_back(y);
		adj[y].push_back(x);

	}

	for(int i = 0 ; i<n ;++i)
	{
		if(!vis[i]){
			mn = inf;
		 dfs(i , a);
			ans += mn;
		}
	}

	cout << ans << '\n';
	return 0;
}


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

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());
int  pow(int x,int n) {int res=1; while(n){if(n&1) res=(res*x);x=(x*x);n>>=1;}return res;}

vector<vector<int >> adj;
vector<bool > vis;
vector<int >a;

int ans = 0;
int mn;
void dfs(int src , vector<int >&a)
{
	vis[src] = 1;
	for(auto u : adj[src])
	{
		if(!vis[u]){
			mn = min(mn, a[u]);
			dfs(u , a);
		}
	}
}
int bfs(int src)
{
	vis[src] = 1;
	queue<int >q;

	q.push(src);
	mn = a[src];
	while(!q.empty())
	{
		int u = q.front();
		q.pop();
		mn = min(mn, a[u]);
	for(auto &u : adj[src])
	{
		if(!vis[u])
		{
			vis[u] = 1;
			q.push(u);
		}
	}

	}

	return mn;
}
int32_t main()
{
	FIO;
	int n, m;
	cin >> n >> m;
	adj.resize(n);
	vis.resize(n);
	a.resize(n);
	for(int i=0 ; i<n ;++i)
		cin >> a[i];

	for(int i=0 ; i<m ;++i)
	{
		int x, y;
		cin >> x >> y;
		--x;
		--y;
		adj[x].push_back(y);
		adj[y].push_back(x);

	}

	for(int i = 0 ; i<n ;++i)
	{
		if(!vis[i]){
		 mn = inf;
		 // dfs(i , a);
			ans += bfs(i);
		}
	}

	cout << ans << '\n';
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
vector<long int> g[100007];
int visited[100007];
long int sum=0;
long int ctr[100007];
long int dfs(long int node,long int parent)
{
   long int c=0,answer=LONG_MAX;

    for(long int j:g[node])
    {

        if(j!=parent)
        {
            visited[j]=1;
          answer=min(answer,dfs(j,node));
            c++;
        }

    }
    if(c==0)
    return ctr[node];
    else return answer;

}

int main()
{
  long  int n,m,x,y,output,answer,i;
   cin>>n>>m;

   for(i=1;i<=n;i++)
   {

      cin>>ctr[i];

   }

   for(i=1;i<=m;i++)
   {
     cin>>x>>y;
     g[x].push_back(y);
     g[y].push_back(x);
   }
   for(i=1;i<=n;i++)
   {
     if(visited[i]==0)
     {
          visited[i]=1;
         answer=dfs(i,0);
         answer=min(ctr[i],answer);
         sum+=answer;
     }
   }
   cout<<sum;

  return 0;
}


#include<bits/stdc++.h>
using namespace std;
vector<long int> g[100007];
int visited[100007];
long int sum=0;
long int ctr[100007];
long long int dfs(long int node,long int parent)
{
   long int c=0;
   long long answer=100000000000005;

    for(long int j:g[node])
    {

        if(j!=parent)
        {
            visited[j]=1;
          answer=min(answer,dfs(j,node));
            c++;
        }

    }
    if(c==0)
    return ctr[node];
    else return answer;

}

int main()
{
  long  int n,m,x,y,output,answer,i;
   cin>>n>>m;

   for(i=1;i<=n;i++)
   {

      cin>>ctr[i];

   }

   for(i=1;i<=m;i++)
   {
     cin>>x>>y;
     g[x].push_back(y);
     g[y].push_back(x);
   }
   for(i=1;i<=n;i++)
   {
     if(visited[i]==0)
     {
          visited[i]=1;
         answer=dfs(i,0);
         answer=min(ctr[i],answer);
         sum+=answer;
     }
   }
   cout<<sum;

  return 0;
}


#include<bits/stdc++.h>
using namespace std;
vector<int> g[100007];
int visited[100007];
long long int sum=0;
long int answer;
long int ctr[100007];
void dfs( int node)
{

    for(int j:g[node])
    {

        if(visited[j]==0)
        {
            answer=min(ctr[j],answer);
            visited[j]=1;
            dfs(j);

        }

    }

}

int main()
{
   int n,m,x,y,output,i;
   long  int answer;
   cin>>n>>m;

   for(i=1;i<=n;i++)
   {

      cin>>ctr[i];

   }

   for(i=1;i<=m;i++)
   {
     cin>>x>>y;
     g[x].push_back(y);
     g[y].push_back(x);
   }
   for(i=1;i<=n;i++)
   {
     if(visited[i]==0)
     {
         answer=1000000007;
          visited[i]=1;
         dfs(i);
         answer=min(ctr[i],answer);
         sum+=answer;
     }

   }
   cout<<sum;

  return 0;
}


#include<bits/stdc++.h>
using namespace std;
vector<long int> g[100007];
int visited[100007];
long int sum=0;
long int ctr[100007];
long int dfs(long int node,long int parent)
{
   long int c=0;
   long long answer=100000000000005;

    for(long int j:g[node])
    {

        if(j!=parent)
        {
            visited[j]=1;
          answer=min(answer,dfs(j,node));
            c++;
        }

    }
    if(c==0)
    return ctr[node];
    else return answer;

}

int main()
{
  long  int n,m,x,y,output,answer,i;
   cin>>n>>m;

   for(i=1;i<=n;i++)
   {

      cin>>ctr[i];

   }

   for(i=1;i<=m;i++)
   {
     cin>>x>>y;
     g[x].push_back(y);
     g[y].push_back(x);
   }
   for(i=1;i<=n;i++)
   {
     if(visited[i]==0)
     {
          visited[i]=1;
         answer=dfs(i,0);
         answer=min(ctr[i],answer);
         sum+=answer;
     }
   }
   cout<<sum;

  return 0;
}


#include<bits/stdc++.h>
using namespace std;
vector<long int> g[100007];
int visited[100007];
long long int sum=0;
long long int ctr[100007];
long long int dfs(long int node,long int parent)
{
   long int c=0;
   long long int answer=100000000000005;

    for(long int j:g[node])
    {

        if(j!=parent)
        {
            visited[j]=1;
          answer=min(answer,dfs(j,node));
            c++;
        }

    }
    answer=min(ctr[node],answer);
    if(c==0)
    return ctr[node];
    else return answer;

}

int main()
{
  long long int n,m,x,y,output,answer,i;
   cin>>n>>m;

   for(i=1;i<=n;i++)
   {

      cin>>ctr[i];

   }

   for(i=1;i<=m;i++)
   {
     cin>>x>>y;
     g[x].push_back(y);
     g[y].push_back(x);
   }
   for(i=1;i<=n;i++)
   {
     if(visited[i]==0)
     {
          visited[i]=1;
         answer=dfs(i,0);
         answer=min(ctr[i],answer);
         sum+=answer;
     }

   }
   cout<<sum;

  return 0;
}


#include<bits/stdc++.h>
using namespace std;
vector<int> g[100007];
int visited[100007];
long long int sum=0;
long int ctr[100007];
long int dfs( int node, int parent)
{
    int c=0;
   long int answer=100007;

    for(int j:g[node])
    {

        if(j!=parent)
        {
            visited[j]=1;
          answer=min(answer,dfs(j,node));
            c++;
        }

    }
    answer=min(ctr[node],answer);
    if(c==0)
    return ctr[node];
    else return answer;

}

int main()
{
   int n,m,x,y,output,i;
   long  int answer;
   cin>>n>>m;

   for(i=1;i<=n;i++)
   {

      cin>>ctr[i];

   }

   for(i=1;i<=m;i++)
   {
     cin>>x>>y;
     g[x].push_back(y);
     g[y].push_back(x);
   }
   for(i=1;i<=n;i++)
   {
     if(visited[i]==0)
     {
          visited[i]=1;
         answer=dfs(i,0);
         answer=min(ctr[i],answer);
         sum+=answer;
     }

   }
   cout<<sum;

  return 0;
}


#include<bits/stdc++.h>
using namespace std;
vector<int> g[100007];
int visited[100007];
long long int sum=0;
long int ctr[100007];
long int dfs( int node, int parent)
{
    int c=0;
   long int answer=100000000000005;

    for(int j:g[node])
    {

        if(j!=parent)
        {
            visited[j]=1;
          answer=min(answer,dfs(j,node));
            c++;
        }

    }
    answer=min(ctr[node],answer);
    if(c==0)
    return ctr[node];
    else return answer;

}

int main()
{
   int n,m,x,y,output,i;
   long int answer;
   cin>>n>>m;

   for(i=1;i<=n;i++)
   {

      cin>>ctr[i];

   }

   for(i=1;i<=m;i++)
   {
     cin>>x>>y;
     g[x].push_back(y);
     g[y].push_back(x);
   }
   for(i=1;i<=n;i++)
   {
     if(visited[i]==0)
     {
          visited[i]=1;
         answer=dfs(i,0);
         answer=min(ctr[i],answer);
         sum+=answer;
     }

   }
   cout<<sum;

  return 0;
}


#include<bits/stdc++.h>
using namespace std;
vector<int> g[100007];
int visited[100007];
long long int sum=0;
long long int ctr[100007];
long long int dfs( int node, int parent)
{
    int c=0;
   long long int answer=100000000000005;

    for(int j:g[node])
    {

        if(j!=parent)
        {
            visited[j]=1;
          answer=min(answer,dfs(j,node));
            c++;
        }

    }
    answer=min(ctr[node],answer);
    if(c==0)
    return ctr[node];
    else return answer;

}

int main()
{
   int n,m,x,y,output,i;
   long long int answer;
   cin>>n>>m;

   for(i=1;i<=n;i++)
   {

      cin>>ctr[i];

   }

   for(i=1;i<=m;i++)
   {
     cin>>x>>y;
     g[x].push_back(y);
     g[y].push_back(x);
   }
   for(i=1;i<=n;i++)
   {
     if(visited[i]==0)
     {
          visited[i]=1;
         answer=dfs(i,0);
         answer=min(ctr[i],answer);
         sum+=answer;
     }

   }
   cout<<sum;

  return 0;
}


#include <cstdio>
#include <queue>
#include <algorithm>
using namespace std;
#define Maxn 400000
priority_queue<int,vector<int>,greater<int> > q;
vector<int> ed[Maxn+5];
int in[Maxn+5];
int ans[Maxn+5];
int main(){
	int n,m;
	scanf("%d%d",&n,&m);
	int u,v;
	for(int i=1;i<n;i++){
		scanf("%d%d",&u,&v);
		ed[u].push_back(v);
		ed[v].push_back(u);
		in[u]++;
		in[v]++;
	}
	for(int i=1;i<=n;i++){
		if(in[i]==1){
			q.push(i);
		}
	}
	int len=0;
	int now;
	while(m--){
		now=q.top();
		q.pop();
		ans[++len]=now;
		for(int i=0;i<(int)ed[now].size();i++){
			in[ed[now][i]]--;
			if(in[ed[now][i]]==1){
				q.push(ed[now][i]);
			}
		}
	}
	sort(ans+1,ans+1+len);
	for(int i=1;i<=len;i++){
		printf("%d ",ans[i]);
	}
	puts("");
	return 0;
}


#include <cstdio>
#include <vector>
using namespace std;
#define Maxn 1000000
vector<int> ed[Maxn+5];
int n,m;
int fa[Maxn+5];
bool can[Maxn+5];
int sz[Maxn+5];
int f[Maxn+5];
int dfn[Maxn+5];
int dep[Maxn+5];
void add(int x,int a){
	for(int i=x;i<=n;i+=(i&(-i))){
		f[i]+=a;
	}
}
int sum(int x){
	int ans=0;
	for(int i=x;i>0;i-=(i&(-i))){
		ans+=f[i];
	}
	return ans;
}
int tot;
void dfs(int x){
	sz[x]=1;
	dep[x]=dep[fa[x]]+1;
	dfn[x]=++tot;
	for(int i=0;i<(int)ed[x].size();i++){
		if(ed[x][i]!=fa[x]){
			fa[ed[x][i]]=x;
			dfs(ed[x][i]);
			sz[x]+=sz[ed[x][i]];
		}
	}
}
int find(int x){
	return dep[x]+sum(dfn[x]);
}
void work(int x){
	if(can[x]){
		return;
	}
	work(fa[x]);
	can[x]=1;
	add(dfn[x],-1);
	add(dfn[x]+sz[x],1);
}
int ans[Maxn+5];
int main(){
	scanf("%d%d",&n,&m);
	int u,v;
	for(int i=1;i<n;i++){
		scanf("%d%d",&u,&v);
		ed[u].push_back(v);
		ed[v].push_back(u);
	}
	can[0]=1;
	dfs(n);
	work(n);
	int now=1,tmp;
	int len=0;
	for(int i=n-1;i>0;i--){
		if(can[i]){
			continue;
		}
		tmp=find(i);
		if(now+tmp<=n-m){
			now+=tmp;
			work(i);
		}
		else{
			ans[++len]=i;
		}
	}
	for(int i=len;i>0;i--){
		printf("%d ",ans[i]);
	}
	puts("");
	return 0;
}


#include <cstdio>
#include <vector>
using namespace std;
#define Maxn 1000000
vector<int> ed[Maxn+5];
int n,m;
int fa[Maxn+5];
bool can[Maxn+5];
int b[Maxn+5][35];
int sum[Maxn+5];
void dfs(int x){
	sum[x]=sum[fa[x]]+1;
	for(int i=0;i<(int)ed[x].size();i++){
		if(ed[x][i]!=fa[x]){
			fa[ed[x][i]]=x;
			dfs(ed[x][i]);
		}
	}
}
void init(){
	for(int i=1;i<=n;i++){
		b[i][0]=fa[i];
	}
	for(int j=1;j<=30;j++){
		for(int i=1;i<=n;i++){
			b[i][j]=b[b[i][j-1]][j-1];
		}
	}
}
int find(int x){
	int now=x;
	for(int j=30;j>=0;j--){
		if(!can[b[now][j]]){
			now=b[now][j];
		}
	}
	return sum[x]-sum[fa[now]];
}
void work(int x){
	if(can[x]){
		return;
	}
	work(fa[x]);
	can[x]=1;
}
int ans[Maxn+5];
int main(){
	scanf("%d%d",&n,&m);
	int u,v;
	for(int i=1;i<n;i++){
		scanf("%d%d",&u,&v);
		ed[u].push_back(v);
		ed[v].push_back(u);
	}
	can[n]=can[0]=1;
	dfs(n);
	init();
	int now=1,tmp;
	int len=0;
	for(int i=n-1;i>0;i--){
		if(can[i]){
			continue;
		}
		tmp=find(i);
		if(now+tmp<=n-m){
			now+=tmp;
			work(i);
		}
		else{
			ans[++len]=i;
		}
	}
	for(int i=len;i>0;i--){
		printf("%d ",ans[i]);
	}
	puts("");
	return 0;
}


#include <cstdio>
#include <vector>
using namespace std;
#define Maxn 1000000
vector<int> ed[Maxn+5];
int n,m;
int fa[Maxn+5];
bool can[Maxn+5];
void dfs(int x){
	for(int i=0;i<(int)ed[x].size();i++){
		if(ed[x][i]!=fa[x]){
			fa[ed[x][i]]=x;
			dfs(ed[x][i]);
		}
	}
}
int find(int x){
	if(can[x]){
		return 0;
	}
	return find(fa[x])+1;
}
void work(int x){
	if(can[x]){
		return;
	}
	work(fa[x]);
	can[x]=1;
}
int ans[Maxn+5];
int main(){
	scanf("%d%d",&n,&m);
	int u,v;
	for(int i=1;i<n;i++){
		scanf("%d%d",&u,&v);
		ed[u].push_back(v);
		ed[v].push_back(u);
	}
	can[n]=1;
	dfs(n);
	int now=1,tmp;
	int len=0;
	for(int i=n-1;i>0;i--){
		if(can[i]){
			continue;
		}
		tmp=find(i);
		if(now+tmp<=n-m){
			now+=tmp;
			work(i);
		}
		else{
			ans[++len]=i;
		}
	}
	for(int i=len;i>0;i--){
		printf("%d ",ans[i]);
	}
	puts("");
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn=1e6+1;
const int maxnlog=20+1;
int father[maxn][maxnlog];
int depth[maxn];
int n,m,root;
int  book[maxn];
vector<int>G[maxn];
void dfs(int x,int f,int dis)
{
    father[x][0]=f;
    depth[x]=dis;
    for(auto i:G[x]){
            if(i==f)continue;
        dfs(i,x,dis+1);
    }

}
void init()
{
    dfs(root,-1,0);

    for(int j=0;j+1<maxnlog;j++)
        for(int i=1;i<=n;i++){
        if(father[i][j]<0)father[i][j+1]=-1;
        else father[i][j+1]=father[father[i][j]][j];
    }
}
int main()
{

        cin>>n>>m;
        for(int i=1;i<n;i++)
        {
            int x,y;
            scanf("%d%d",&x,&y);
            G[x].push_back(y);
            G[y].push_back(x);
        }

        root=n;

        int cnt=n-m-1;

        init();
        book[n]=true;
        for(int cur=root-1;cur>0;cur--){

            if(book[cur])continue;
            int u=cur;
            for(int i=maxnlog-1;i>=0;i--){
                if(father[u][i]!=-1 and not book[father[u][i]])
                    u=father[u][i];
            }
            if(depth[cur]-depth[u]+1>cnt)continue;
            int t=cur;
            while(true){
                book[t]=true;
                cnt--;
                if(t==u)break;
                t=father[t][0];
            }

        }
        for(int i=1;i<=n;i++)
        {
            if(book[i])
                continue;
                printf("%d ",i);

        }
}


#include<bits/stdc++.h>
using namespace std;
const int maxn=1e6+1;
const int maxnlog=20+1;
int father[maxn][maxnlog];
int depth[maxn];
int n,m,root;
int  book[maxn];
vector<int>G[maxn];
void dfs(int x,int f,int dis)
{
    father[x][0]=f;
    depth[x]=dis;
    for(auto i:G[x]){
            if(i==f)continue;
        dfs(i,x,dis+1);
    }

}
void init()
{
    dfs(root,-1,0);

    for(int j=0;j+1<maxnlog;j++)
        for(int i=1;i<=n;i++){
        if(father[i][j]<0)father[i][j+1]=-1;
        else father[i][j+1]=father[father[i][j]][j];
    }
}
int main()
{
    ios::sync_with_stdio(false);
        cin>>n>>m;
        for(int i=1;i<n;i++)
        {
            int x,y;
            scanf("%d%d",&x,&y);
            G[x].push_back(y);
            G[y].push_back(x);
        }

        root=n;

        int cnt=n-m-1;

        init();
        book[n]=true;
        for(int cur=root-1;cur>0;cur--){

            if(book[cur])continue;
            int u=cur;
            for(int i=maxnlog-1;i>=0;i--){
                if(father[u][i]!=-1 and not book[father[u][i]])
                    u=father[u][i];
            }
            if(depth[cur]-depth[u]+1>cnt)continue;
            int t=cur;
            while(true){
                book[t]=true;
                cnt--;
                if(t==u)break;
                t=father[t][0];
            }

        }
        for(int i=1;i<=n;i++)
        {
            if(book[i])
                continue;
                printf("%d ",i);

        }
}


#include<bits/stdc++.h>
using namespace std;
const int maxn=1e6+1;
const int maxnlog=20+1;
int father[maxn][maxnlog];
int depth[maxn];
int n,m,root;
int  book[maxn];
vector<int>G[maxn];
void dfs(int x,int f,int dis)
{
    father[x][0]=f;
    depth[x]=dis;
    for(auto i:G[x]){
            if(i==f)continue;
        dfs(i,x,dis+1);
    }

}
void init()
{
    dfs(root,-1,0);

    for(int j=0;j+1<maxnlog;j++)
        for(int i=1;i<=n;i++){
        if(father[i][j]<0)father[i][j+1]=-1;
        else father[i][j+1]=father[father[i][j]][j];
    }
}
int main()
{
    ios::sync_with_stdio(false);
        cin>>n>>m;
        for(int i=1;i<n;i++)
        {
            int x,y;
            cin>>x>>y;
            G[x].push_back(y);
            G[y].push_back(x);
        }

        root=n;

        int cnt=n-m-1;

        init();
        book[n]=true;
        for(int cur=root-1;cur>0;cur--){

            if(book[cur])continue;
            int u=cur;
            for(int i=maxnlog-1;i>=0;i--){
                if(father[u][i]!=-1 and not book[father[u][i]])
                    u=father[u][i];
            }
            if(depth[cur]-depth[u]+1>cnt)continue;
            int t=cur;
            while(true){
                book[t]=true;
                cnt--;
                if(t==u)break;
                t=father[t][0];
            }

        }
        for(int i=1;i<=n;i++)
        {
            if(book[i])
                continue;
                cout<<i<<' ';;

        }
}


#include<bits/stdc++.h>

using namespace std;

const int maxn = int(1e6) + 5;

const int maxlogn = int(20) + 5;

int n, m, root;

vector<int> G[maxn];

int parent[maxlogn][maxn]; // 向上走 pow(2, k) 步走到的节点

int depth[maxn];

void dfs(int u, int p, int d)
{

    parent[0][u] = p;

    depth[u] = d;

    for (auto v : G[u]) {

    if (v == p) continue;

    dfs(v, u, d + 1);

    }

}

void init()
{

    dfs(root, -1, 0);

    for (int k = 0; k + 1 < maxlogn; k++) {

    for (int v = 1; v <= n; v++) {

        if (parent[k][v] < 0) parent[k+1][v] = -1;
        else parent[k+1][v] = parent[k][parent[k][v]];

        }

    }

}

int book[maxn];

int main() {

ios::sync_with_stdio(false);

cin >> n >> m;

for (int i = 1; i < n; i++) {

    int u, v;

    cin >> u >> v;

    G[u].push_back(v);

    G[v].push_back(u);

    }

root = n;

int cnt = n - m - 1;

init();

book[n] = true;

for (int cur = root - 1; cur > 0; cur--) {
        if (book[cur]) continue;

    int u = cur;

    for (int i = maxlogn - 1; i >= 0; i--) {

    if (parent[i][u] != -1 and not book[parent[i][u]]) { u = parent[i][u];

        }

    }

        if (depth[cur] - depth[u] + 1 > cnt) continue;

        //	find cur -> u
        int t = cur;

        while (true) {

            book[t] = true, cnt--;
        if (t == u) break;

        t = parent[0][t];

        }

}

    for (int i = 1; i <= n; i++) {

    if (book[i]) continue;

    cout << i << " ";

    }

    cout << endl;

}


#include<bits/stdc++.h>
using namespace std;
const int maxn=1e6+1;
const int maxnlog=20+1;
int father[maxn][maxnlog];
int depth[maxn];
int n,m,root;
int  book[maxn];
vector<int>G[maxn];
void dfs(int x,int f,int dis)
{
    father[x][0]=f;
    depth[x]=dis;
    for(auto i:G[x]){
            if(i==f)continue;
        dfs(i,x,dis+1);
    }

}
void init()
{
    dfs(root,-1,0);

    for(int j=0;j+1<maxnlog;j++)
        for(int i=1;i<=n;i++){
        if(father[i][j]<0)father[i][j+1]=-1;
        else father[i][j+1]=father[father[i][j]][j];
    }
}
int main()
{
    ios::sync_with_stdio(false);
        cin>>n>>m;
        for(int i=1;i<n;i++)
        {
            int x,y;
            cin>>x>>y;
            G[x].push_back(y);
            G[y].push_back(x);
        }

        root=n;

        int cnt=n-m-1;

        init();
        book[n]=true;
        for(int cur=root-1;cur>0;cur--){

            if(book[cur])continue;
            int u=cur;
            for(int i=maxnlog-1;i>=0;i--){
                if(father[u][i]!=-1 and not book[father[u][i]])
                    u=father[u][i];
            }
            if(depth[cur]-depth[u]+1>cnt)continue;
            int t=cur;
            while(true){
                book[t]=true;
                cnt--;
                if(t==u)break;
                t=father[t][0];
            }

        }
        for(int i=1;i<=n;i++)
        {
            if(book[i])
                continue;
                cout<<i<<' ';

        }
}


#include<bits/stdc++.h>
using namespace std;
const int maxn=1e6+3;
const int maxnlog=20+1;
vector<int>G[maxn];
int father[maxn][maxnlog];
int depth[maxn];
int n,m;
void dfs(int x,int f,int d)
{
    father[x][0]=f;
    depth[x]=d;
    for(auto v:G[x])
    {
        if(v==f)continue;
        dfs(v,x,d+1);
    }
}
void init()
{
    dfs(n,-1,0);
    for(int i=0;i+1<maxnlog;i++)
    for(int j=1;j<=n;j++){
        if(father[j][i]<0)father[j][i+1]=-1;
            else father[j][i+1]=father[father[j][i]][i];
    }
}
int book[maxn];
int main()
{
    cin>>n>>m;
    for(int i=1;i<n;i++){
        int x,y;
        scanf("%d%d",&x,&y);
        G[x].push_back(y);
        G[y].push_back(x);
    }
    int root=n;
    int cnt=root-m-1;
    init();
    book[n]=true;
    for(int cur=root-1;cur>0;cur--){
        if(book[cur])continue;
        int u=cur;
        for(int i=maxnlog-1;i>=0;i--){
            if(father[u][i]!=-1 and not book[father[u][i]])
                u=father[u][i];
        }
        if(depth[cur]-depth[u]+1>cnt) continue;

        int t=cur;
        while(true){
            book[t]=true;
            cnt--;
            if(t==u)break;
            t=father[t][0];
        }
    }
    for(int i=1;i<=n;i++)
    {
            if(!book[i])
            printf("%d ",i);
    }
}


#include<bits/stdc++.h>
using namespace std;
const int maxn=1e6+1;
const int maxnlog=20+1;
int father[maxn][maxnlog];
int depth[maxn];
int n,m,root;
bool book[maxn];
vector<int>G[maxn];
void dfs(int x,int f,int dis)
{
    father[x][0]=f;
    depth[x]=dis;
    for(auto i:G[x]){
            if(i==f)continue;
        dfs(i,x,dis+1);
    }

}
void init()
{
    dfs(n,-1,0);
    for(int i=1;i<=n;i++)
    for(int j=0;j+1<maxnlog;j++){
        if(father[i][j]<0)father[i][j+1]=-1;
        else father[i][j+1]=father[father[i][j]][j];
    }
}
int main()
{
    ios::sync_with_stdio(false);
        cin>>n>>m;
        for(int i=1;i<n;i++)
        {
            int x,y;
            cin>>x>>y;
            G[x].push_back(y);
            G[y].push_back(x);
        }

        root=n;

        int cnt=n-m-1;

        init();
        book[n]=true;
        for(int cur=root-1;cur>0;cur--){

            if(book[cur])continue;
            int u=cur;
            for(int i=maxnlog-1;i>=0;i--){
                if(father[cur][i]!=-1 and not book[father[cur][i]])
                    u=father[cur][i];
            }
            if(depth[cur]-depth[u]+1>cnt)continue;
            int t=cur;
            while(true){
                book[t]=true;
                cnt--;
                if(t==u)break;
                t=father[t][0];
            }

        }
        for(int i=1;i<=n;i++)
        {
            if(!book[i]){
                cout<<i<<' ';
            }
        }
}


#include<bits/stdc++.h>

#define file(s) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
#define go(x, i) for(register int i = head[x]; i; i = nxt[i])
#define For(i, a, b) for(register int i = (a), i##_end_ = (b); i <= i##_end_; ++ i)
#define FOR(i, a, b) for(register int i = (a), i##_end_ = (b); i >= i##_end_; -- i)
#define debug(x) cout << #x << " = " << x << endl
#define mem(a, b) memset(a, b, sizeof(a))
#define cpy(a, b) memcpy(a, b, sizeof(a))
#define inf (0x3f3f3f3f)
#define INF (1e18)
#define pb push_back
#define mp make_pair
#define x first
#define y second
#define y1 orzorz

typedef unsigned long long ull;
typedef unsigned int uint;
typedef long long ll;
typedef std::pair<ll, int> PLI;
typedef std::pair<int, int> PII;
typedef long double ldb;
typedef double db;

namespace IO {
#define getc() ((S_ == T_) && (T_ = (S_ = Ch_) + fread(Ch_, 1, Buffsize, stdin), S_ == T_) ? 0 : *S_ ++)
#define putc(x) *nowps ++ = (x)

	const uint Buffsize = 1 << 15, Output = 1 << 23;
	static char Ch_[Buffsize], *S_ = Ch_, *T_ = Ch_;
	static char Out[Output], *nowps = Out;

	inline void flush() {fwrite(Out, 1, nowps - Out, stdout); nowps = Out;}
	template<class T>inline bool chkmax(T &_, T __) {return _ < __ ? _ = __, 1 : 0;}
	template<class T>inline bool chkmin(T &_, T __) {return _ > __ ? _ = __, 1 : 0;}

	template<class T>inline void read(T &_) {
		_ = 0; static char __; T ___ = 1;
		for(__ = getc(); !isdigit(__); __ = getc()) if(__ == '-') ___ = -1;
		for(; isdigit(__); __ = getc()) _ = (_ << 3) + (_ << 1) + (__ ^ 48);
		_ *= ___;
	}

	template<class T>inline void write(T _, char __ = '\n') {
		if(!_) putc('0');
		if(_ < 0) putc('-'), _ = -_;
		static uint sta[111], tp;
		for(tp = 0; _; _ /= 10) sta[++ tp] = _ % 10;
		for(; tp; putc(sta[tp --] ^ 48)); putc(__);
	}

	inline void procStatus() {
		std::ifstream t("/proc/self/status");
		std::cerr << std::string(std::istreambuf_iterator<char>(t), std::istreambuf_iterator<char>());
	}
}

using namespace std;
using namespace IO;

const int N = 1e6 + 10;

int fa[N][21], dep[N], ans[N], vis[N], n, k;
int to[N << 1], nxt[N << 1], head[N], e;

void add(int x, int y) {
	to[++ e] = y; nxt[e] = head[x]; head[x] = e;
}

void dfs(int x, int dad) {
	fa[x][0] = dad;
	For(j, 1, 20) fa[x][j] = fa[fa[x][j - 1]][j - 1];
	go(x, i) if(to[i] ^ dad) dfs(to[i], x);
}

int main() {
#ifdef ylsakioi
	file("cf980e");
#endif

	set<int> S;

	int x, y, rest;

	read(n), read(k), rest = n - k;
	For(i, 1, n) S.insert(i);
	For(i, 2, n) {
		read(x), read(y);
		add(x, y), add(y, x);
	}

	dfs(n, 0);

	while(rest) {
		int now = x = *S.rbegin(), sum = 1;
		FOR(j, 20, 0) if(fa[x][j] && !vis[fa[x][j]])
			x = fa[x][j], sum += 1 << j;
		if(sum <= rest) for(; now && !vis[now]; now = fa[now][0])
			-- rest, S.erase(now), vis[now] = 1, ans[++ ans[0]] = now;
		else S.erase(now);
	}

	For(i, 1, n) if(!vis[i]) write(i);

	return flush(), 0;
}


#include<bits/stdc++.h>

#define file(s) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
#define go(x, i) for(register int i = head[x]; i; i = nxt[i])
#define For(i, a, b) for(register int i = (a), i##_end_ = (b); i <= i##_end_; ++ i)
#define FOR(i, a, b) for(register int i = (a), i##_end_ = (b); i >= i##_end_; -- i)
#define debug(x) cout << #x << " = " << x << endl
#define mem(a, b) memset(a, b, sizeof(a))
#define cpy(a, b) memcpy(a, b, sizeof(a))
#define inf (0x3f3f3f3f)
#define INF (1e18)
#define pb push_back
#define mp make_pair
#define x first
#define y second
#define y1 orzorz

typedef unsigned long long ull;
typedef unsigned int uint;
typedef long long ll;
typedef std::pair<ll, int> PLI;
typedef std::pair<int, int> PII;
typedef long double ldb;
typedef double db;

namespace IO {
#define getc() ((S_ == T_) && (T_ = (S_ = Ch_) + fread(Ch_, 1, Buffsize, stdin), S_ == T_) ? 0 : *S_ ++)
#define putc(x) *nowps ++ = (x)

	const uint Buffsize = 1 << 15, Output = 1 << 23;
	static char Ch_[Buffsize], *S_ = Ch_, *T_ = Ch_;
	static char Out[Output], *nowps = Out;

	inline void flush() {fwrite(Out, 1, nowps - Out, stdout); nowps = Out;}
	template<class T>inline bool chkmax(T &_, T __) {return _ < __ ? _ = __, 1 : 0;}
	template<class T>inline bool chkmin(T &_, T __) {return _ > __ ? _ = __, 1 : 0;}

	template<class T>inline void read(T &_) {
		_ = 0; static char __; T ___ = 1;
		for(__ = getc(); !isdigit(__); __ = getc()) if(__ == '-') ___ = -1;
		for(; isdigit(__); __ = getc()) _ = (_ << 3) + (_ << 1) + (__ ^ 48);
		_ *= ___;
	}

	template<class T>inline void write(T _, char __ = '\n') {
		if(!_) putc('0');
		if(_ < 0) putc('-'), _ = -_;
		static uint sta[111], tp;
		for(tp = 0; _; _ /= 10) sta[++ tp] = _ % 10;
		for(; tp; putc(sta[tp --] ^ 48)); putc(__);
	}

	inline void procStatus() {
		std::ifstream t("/proc/self/status");
		std::cerr << std::string(std::istreambuf_iterator<char>(t), std::istreambuf_iterator<char>());
	}
}

using namespace std;
using namespace IO;

const int N = 1e6 + 10;

int to[N << 1], nxt[N << 1], head[N], e;
int fa[N], de[N], ans[N], n, k;

void add(int x, int y) {
	to[++ e] = y; nxt[e] = head[x]; head[x] = e;
}

void dfs(int x, int dad) {
	go(x, i) if(to[i] ^ dad) {
		++ de[x], fa[to[i]] = x;
		dfs(to[i], x);
	}
}

void TopSort() {
	priority_queue<int, vector<int>, greater<int> > q;
	For(i, 1, n) if(!de[i]) q.push(i);
	while(!q.empty() && k --) {
		int x = q.top(); q.pop(); ans[++ ans[0]] = x;
		if(!(-- de[fa[x]])) q.push(fa[x]);
	}
	sort(ans + 1, ans + ans[0] + 1);
	For(i, 1, ans[0]) write(ans[i]);
}

int main() {
#ifdef ylsakioi
	file("cf980e");
#endif

	int x, y;

	read(n), read(k);
	For(i, 2, n) {
		read(x), read(y);
		add(x, y), add(y, x);
	}

	dfs(n, 0), TopSort();

	return flush(), 0;
}


#include<bits/stdc++.h>
#include<bits/extc++.h>

#define file(s) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
#define go(x, i) for(register int i = head[x]; i; i = nxt[i])
#define For(i, a, b) for(register int i = (a), i##_end_ = (b); i <= i##_end_; ++ i)
#define FOR(i, a, b) for(register int i = (a), i##_end_ = (b); i >= i##_end_; -- i)
#define debug(x) cout << #x << " = " << x << endl
#define mem(a, b) memset(a, b, sizeof(a))
#define cpy(a, b) memcpy(a, b, sizeof(a))
#define inf (0x3f3f3f3f)
#define INF (1e18)
#define pb push_back
#define mp make_pair
#define x first
#define y second
#define y1 orzorz

typedef unsigned long long ull;
typedef unsigned int uint;
typedef long long ll;
typedef std::pair<ll, int> PLI;
typedef std::pair<int, int> PII;
typedef long double ldb;
typedef double db;

namespace IO {
#define getc() ((S_ == T_) && (T_ = (S_ = Ch_) + fread(Ch_, 1, Buffsize, stdin), S_ == T_) ? 0 : *S_ ++)
#define putc(x) *nowps ++ = (x)

	const uint Buffsize = 1 << 15, Output = 1 << 23;
	static char Ch_[Buffsize], *S_ = Ch_, *T_ = Ch_;
	static char Out[Output], *nowps = Out;

	inline void flush() {fwrite(Out, 1, nowps - Out, stdout); nowps = Out;}
	template<class T>inline bool chkmax(T &_, T __) {return _ < __ ? _ = __, 1 : 0;}
	template<class T>inline bool chkmin(T &_, T __) {return _ > __ ? _ = __, 1 : 0;}

	template<class T>inline void read(T &_) {
		_ = 0; static char __; T ___ = 1;
		for(__ = getc(); !isdigit(__); __ = getc()) if(__ == '-') ___ = -1;
		for(; isdigit(__); __ = getc()) _ = (_ << 3) + (_ << 1) + (__ ^ 48);
		_ *= ___;
	}

	template<class T>inline void write(T _, char __ = '\n') {
		if(!_) putc('0');
		if(_ < 0) putc('-'), _ = -_;
		static uint sta[111], tp;
		for(tp = 0; _; _ /= 10) sta[++ tp] = _ % 10;
		for(; tp; putc(sta[tp --] ^ 48)); putc(__);
	}

	inline void procStatus() {
		std::ifstream t("/proc/self/status");
		std::cerr << std::string(std::istreambuf_iterator<char>(t), std::istreambuf_iterator<char>());
	}
}

using namespace std;
using namespace IO;

const int N = 1e6 + 10;

int fa[N][21], dep[N], ans[N], vis[N], n, k;
int to[N << 1], nxt[N << 1], head[N], e;

void add(int x, int y) {
	to[++ e] = y; nxt[e] = head[x]; head[x] = e;
}

void dfs(int x, int dad) {
	fa[x][0] = dad;
	For(j, 1, 20) fa[x][j] = fa[fa[x][j - 1]][j - 1];
	go(x, i) if(to[i] ^ dad) dfs(to[i], x);
}

int main() {
#ifdef ylsakioi
	file("cf980e");
#endif

	set<int> S;

	int x, y, rest;

	read(n), read(k), rest = n - k;
	For(i, 1, n) S.insert(i);
	For(i, 2, n) {
		read(x), read(y);
		add(x, y), add(y, x);
	}

	dfs(n, 0);

	while(rest) {
		int now = x = *S.rbegin(), sum = 1;
		FOR(j, 20, 0) if(fa[x][j] && !vis[fa[x][j]])
			x = fa[x][j], sum += 1 << j;
		if(sum <= rest) for(; now && !vis[now]; now = fa[now][0])
			-- rest, S.erase(now), vis[now] = 1, ans[++ ans[0]] = now;
		else S.erase(now);
	}

	For(i, 1, n) if(!vis[i]) write(i);

	return flush(), 0;
}


#include<bits/stdc++.h>
#include<bits/extc++.h>

#define file(s) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
#define go(x, i) for(register int i = head[x]; i; i = nxt[i])
#define For(i, a, b) for(register int i = (a), i##_end_ = (b); i <= i##_end_; ++ i)
#define FOR(i, a, b) for(register int i = (a), i##_end_ = (b); i >= i##_end_; -- i)
#define debug(x) cout << #x << " = " << x << endl
#define mem(a, b) memset(a, b, sizeof(a))
#define cpy(a, b) memcpy(a, b, sizeof(a))
#define inf (0x3f3f3f3f)
#define INF (1e18)
#define pb push_back
#define mp make_pair
#define x first
#define y second
#define y1 orzorz

typedef unsigned long long ull;
typedef unsigned int uint;
typedef long long ll;
typedef std::pair<ll, int> PLI;
typedef std::pair<int, int> PII;
typedef long double ldb;
typedef double db;

namespace IO {
#define getc() ((S_ == T_) && (T_ = (S_ = Ch_) + fread(Ch_, 1, Buffsize, stdin), S_ == T_) ? 0 : *S_ ++)
#define putc(x) *nowps ++ = (x)

	const uint Buffsize = 1 << 15, Output = 1 << 23;
	static char Ch_[Buffsize], *S_ = Ch_, *T_ = Ch_;
	static char Out[Output], *nowps = Out;

	inline void flush() {fwrite(Out, 1, nowps - Out, stdout); nowps = Out;}
	template<class T>inline bool chkmax(T &_, T __) {return _ < __ ? _ = __, 1 : 0;}
	template<class T>inline bool chkmin(T &_, T __) {return _ > __ ? _ = __, 1 : 0;}

	template<class T>inline void read(T &_) {
		_ = 0; static char __; T ___ = 1;
		for(__ = getc(); !isdigit(__); __ = getc()) if(__ == '-') ___ = -1;
		for(; isdigit(__); __ = getc()) _ = (_ << 3) + (_ << 1) + (__ ^ 48);
		_ *= ___;
	}

	template<class T>inline void write(T _, char __ = '\n') {
		if(!_) putc('0');
		if(_ < 0) putc('-'), _ = -_;
		static uint sta[111], tp;
		for(tp = 0; _; _ /= 10) sta[++ tp] = _ % 10;
		for(; tp; putc(sta[tp --] ^ 48)); putc(__);
	}

	inline void procStatus() {
		std::ifstream t("/proc/self/status");
		std::cerr << std::string(std::istreambuf_iterator<char>(t), std::istreambuf_iterator<char>());
	}
}

using namespace std;
using namespace IO;

const int N = 1e6 + 10;

int to[N << 1], nxt[N << 1], head[N], e;
int fa[N], de[N], ans[N], n, k;

void add(int x, int y) {
	to[++ e] = y; nxt[e] = head[x]; head[x] = e;
}

void dfs(int x, int dad) {
	go(x, i) if(to[i] ^ dad) {
		++ de[x], fa[to[i]] = x;
		dfs(to[i], x);
	}
}

void TopSort() {
	priority_queue<int, vector<int>, greater<int> > q;
	For(i, 1, n) if(!de[i]) q.push(i);
	while(!q.empty() && k --) {
		int x = q.top(); q.pop(); ans[++ ans[0]] = x;
		if(!(-- de[fa[x]])) q.push(fa[x]);
	}
	sort(ans + 1, ans + ans[0] + 1);
	For(i, 1, ans[0]) write(ans[i]);
}

int main() {
#ifdef ylsakioi
	file("cf980e");
#endif

	int x, y;

	read(n), read(k);
	For(i, 2, n) {
		read(x), read(y);
		add(x, y), add(y, x);
	}

	dfs(n, 0), TopSort();

	return flush(), 0;
}


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

#define fi first
#define se second
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> ii;

const int len = 1e6+6;
int dp[len][25], dep[len], vis[len], p[len];
vector<int> adj[len];

void fix(int u, int d){
    dep[u] = d;
    for (int j = 0; j < adj[u].size(); j++){
        int v = adj[u][j];
        if (p[u] != v){
            p[v] = u;
            fix(v, d+1);
        }
    }
}

int dis(int u){
    //printf("u = %d\n", u);
    int st = u;
    if (vis[u]) return 0;

    int last;
    for (last = 0; (1<<last) <= dep[u]; last++){}
    last--;

    for (int j = last; j >= 0; j--)
        if (!vis[dp[u][j]]) u = dp[u][j];

    //printf("u = %d\n", u);
    return dep[st]+1-dep[u];
}

void path(int u){
    while (!vis[u]) vis[u] = 1;
}

int  main(){
    int n, k;
    scanf("%d %d", &n, &k);
    k = n-k;
    for (int i = 0; i < n-1; i++){
        int a, b;
        scanf("%d %d", &a, &b);
        adj[a].pb(b);
        adj[b].pb(a);
    }

    fix(n, 0);

    for (int i = 1; i <= n; i++)
        dp[i][0] = p[i];
    for (int j = 1; (1<<j) < n; j++)
        for (int i = 1; i <= n; i++)
            if (dp[i][j-1] <= n)
                dp[i][j] = dp[dp[i][j-1]][j-1];

    vis[n] = 1, k--;
    for (int i = n-1; i >= 1; i--){
        //printf("i = %d, k = %d\n", i, k);
        int temp = dis(i);
        if (temp <= k)
            path(i), k -= temp;
        //printf("k now = %d\n", k);
    }

    for (int i = 1; i <= n; i++)
        if (!vis[i]) printf("%d ", i);
    printf("\n");
    return 0;
}


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

#define fi first
#define se second
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> ii;

const int len = 1e6+6;
int dp[len][22], dep[len], vis[len], p[len];
vector<int> adj[len];

void fix(int u, int d){
    dep[u] = d;
    for (int j = 0; j < adj[u].size(); j++){
        int v = adj[u][j];
        if (p[u] != v){
            p[v] = u;
            fix(v, d+1);
        }
    }
}

int dis(int u){
    //printf("u = %d\n", u);
    int st = u;
    if (vis[u]) return 0;

    int last;
    for (last = 0; (1<<last) < dep[u]; last++){}
    last--;

    for (int j = last; j >= 0; j--)
        if (!vis[dp[u][j]]) u = dp[u][j];

    //printf("u = %d\n", u);
    return dep[st]+1-dep[u];
}

void path(int u){
    if (vis[u]) return;
    vis[u] = 1;
    path(p[u]);
}

int  main(){
    int n, k;
    scanf("%d %d", &n, &k);
    k = n-k;
    for (int i = 0; i < n-1; i++){
        int a, b;
        scanf("%d %d", &a, &b);
        adj[a].pb(b);
        adj[b].pb(a);
    }

    fix(n, 0);

    for (int i = 1; i <= n; i++)
        dp[i][0] = p[i];
    for (int j = 1; (1<<j) < n; j++)
        for (int i = 1; i <= n; i++)
            if (dp[i][j-1] <= n)
                dp[i][j] = dp[dp[i][j-1]][j-1];

    vis[n] = 1, k--;
    for (int i = n-1; i >= 1; i--){
        //printf("i = %d, k = %d\n", i, k);
        int temp = dis(i);
        if (temp <= k)
            path(i), k -= temp;
        //printf("k now = %d\n", k);
    }

    for (int i = 1; i <= n; i++)
        if (!vis[i]) printf("%d ", i);
    printf("\n");
    return 0;
}


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

#define fi first
#define se second
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> ii;

const int len = 1e6+6;
int dp[len][25], dep[len], vis[len], p[len];
vector<int> adj[len];

void fix(int u, int d){
    dep[u] = d;
    for (int j = 0; j < adj[u].size(); j++){
        int v = adj[u][j];
        if (p[u] != v){
            p[v] = u;
            fix(v, d+1);
        }
    }
}

int dis(int u){
    //printf("u = %d\n", u);
    int st = u;
    if (vis[u]) return 0;

    int last;
    for (last = 0; (1<<last) <= dep[u]; last++){}
    last--;

    for (int j = last; j >= 0; j--)
        if (!vis[dp[u][j]]) u = dp[u][j];

    //printf("u = %d\n", u);
    return dep[st]+1-dep[u];
}

void path(int u){
    while (!vis[u])
        vis[u] = 1, u = p[u];
}

int  main(){
    int n, k;
    scanf("%d %d", &n, &k);
    k = n-k;
    for (int i = 0; i < n-1; i++){
        int a, b;
        scanf("%d %d", &a, &b);
        adj[a].pb(b);
        adj[b].pb(a);
    }

    fix(n, 0);

    for (int i = 1; i <= n; i++)
        dp[i][0] = p[i];
    for (int j = 1; (1<<j) < n; j++)
        for (int i = 1; i <= n; i++)
            if (dp[i][j-1] <= n)
                dp[i][j] = dp[dp[i][j-1]][j-1];

    vis[n] = 1, k--;
    for (int i = n-1; i >= 1; i--){
        //printf("i = %d, k = %d\n", i, k);
        int temp = dis(i);
        if (temp <= k)
            path(i), k -= temp;
        //printf("k now = %d\n", k);
    }

    for (int i = 1; i <= n; i++)
        if (!vis[i]) printf("%d ", i);
    printf("\n");
    return 0;
}


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

#define fi first
#define se second
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> ii;

const int len = 1e6+6;
int dp[25][len], dep[len], vis[len], p[len];
vector<int> adj[len];

void fix(int u, int d){
    dep[u] = d;
    for (int j = 0; j < adj[u].size(); j++){
        int v = adj[u][j];
        if (p[u] != v){
            p[v] = u;
            fix(v, d+1);
        }
    }
}

int dis(int u){
    //printf("u = %d\n", u);
    int st = u;
    if (vis[u]) return 0;

    int last;
    for (last = 0; (1<<last) <= dep[u]; last++){}
    last--;

    for (int j = last; j >= 0; j--)
        if (dp[j][u] != 0 && !vis[dp[j][u]]) u = dp[j][u];

    //printf("u = %d\n", u);
    return dep[st]+1-dep[u];
}

void path(int u){
    while (!vis[u])
        vis[u] = 1, u = p[u];
}

int  main(){
    int n, k;
    scanf("%d %d", &n, &k);
    k = n-k;
    for (int i = 0; i < n-1; i++){
        int a, b;
        scanf("%d %d", &a, &b);
        adj[a].pb(b);
        adj[b].pb(a);
    }

    fix(n, 0);

    for (int i = 1; i <= n; i++)
        dp[0][i] = p[i];
    for (int j = 1; (1<<j) < n; j++)
        for (int i = 1; i <= n; i++)
            if (dp[j-1][i] > 0)
                dp[j][i] = dp[j-1][dp[j-1][i]];

    vis[n] = 1, k--;
    for (int i = n-1; i >= 1; i--){
        //printf("i = %d, k = %d\n", i, k);
        int temp = dis(i);
        if (temp <= k)
            path(i), k -= temp;
        //printf("k now = %d\n", k);
    }

    for (int i = 1; i <= n; i++)
        if (!vis[i]) printf("%d ", i);
    printf("\n");
    return 0;
}


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

#define fi first
#define se second
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> ii;

const int len = 1e6+6;
int dp[22][len], dep[len], vis[len], p[len];
vector<int> adj[len];

void fix(int u, int d){
    dep[u] = d;
    for (int j = 0; j < adj[u].size(); j++){
        int v = adj[u][j];
        if (p[u] != v){
            p[v] = u;
            fix(v, d+1);
        }
    }
}

int dis(int u){
    //printf("u = %d\n", u);
    int st = u;
    if (vis[u]) return 0;

    int last;
    for (last = 0; (1<<last) <= dep[u]; last++){}
    last--;

    for (int j = last; j >= 0; j--)
        if (dp[j][u] != 0 && !vis[dp[j][u]]) u = dp[j][u];

    //printf("u = %d\n", u);
    return dep[st]+1-dep[u];
}

void path(int u){
    while (!vis[u])
        vis[u] = 1, u = p[u];
}

int  main(){
    int n, k;
    scanf("%d %d", &n, &k);
    k = n-k;
    for (int i = 0; i < n-1; i++){
        int a, b;
        scanf("%d %d", &a, &b);
        adj[a].pb(b);
        adj[b].pb(a);
    }

    fix(n, 0);

    for (int i = 1; i <= n; i++)
        dp[0][i] = p[i];
    for (int j = 1; (1<<j) < n; j++)
        for (int i = 1; i <= n; i++)
            if (dp[j-1][i] > 0)
                dp[j][i] = dp[j-1][dp[j-1][i]];

    vis[n] = 1, k--;
    for (int i = n-1; i >= 1; i--){
        //printf("i = %d, k = %d\n", i, k);
        int temp = dis(i);
        if (temp <= k)
            path(i), k -= temp;
        //printf("k now = %d\n", k);
    }

    for (int i = 1; i <= n; i++)
        if (!vis[i]) printf("%d ", i);
    printf("\n");
    return 0;
}


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

#define fi first
#define se second
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> ii;

const int len = 1e6+6;
int dp[len][25], dep[len], vis[len], p[len];
vector<int> adj[len];

void fix(int u, int d){
    dep[u] = d;
    for (int j = 0; j < adj[u].size(); j++){
        int v = adj[u][j];
        if (p[u] != v){
            p[v] = u;
            fix(v, d+1);
        }
    }
}

int dis(int u){
    //printf("u = %d\n", u);
    int st = u;
    if (vis[u]) return 0;

    int last;
    for (last = 0; (1<<last) <= dep[u]; last++){}
    last--;

    for (int j = last; j >= 0; j--)
        if (!vis[dp[u][j]]) u = dp[u][j];

    //printf("u = %d\n", u);
    return dep[st]+1-dep[u];
}

void path(int u){
    while (!vis[u])
        vis[u] = 1, u = p[u];
}

int  main(){
    int n, k;
    scanf("%d %d", &n, &k);
    k = n-k;
    for (int i = 0; i < n-1; i++){
        int a, b;
        scanf("%d %d", &a, &b);
        adj[a].pb(b);
        adj[b].pb(a);
    }

    fix(n, 0);

    for (int i = 1; i <= n; i++)
        dp[i][0] = p[i];
    for (int j = 1; (1<<j) < n; j++)
        for (int i = 1; i <= n; i++)
            if (dp[i][j-1] > 0)
                dp[i][j] = dp[dp[i][j-1]][j-1];

    vis[n] = 1, k--;
    for (int i = n-1; i >= 1; i--){
        if (k == 0) break;
        if (vis[i]) continue;
        int temp = dis(i);
        if (temp <= k)
            path(i), k -= temp;
        //printf("k now = %d\n", k);
    }

    for (int i = 1; i <= n; i++)
        if (!vis[i]) printf("%d ", i);
    printf("\n");
    return 0;
}


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

#define fi first
#define se second
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> ii;

const int len = 1e6+6;
int dp[len][25], dep[len], vis[len], p[len];
vector<int> adj[len];

void fix(int u, int d){
    dep[u] = d;
    for (int j = 0; j < adj[u].size(); j++){
        int v = adj[u][j];
        if (p[u] != v){
            p[v] = u;
            fix(v, d+1);
        }
    }
}

int dis(int u){
    //printf("u = %d\n", u);
    int st = u;
    if (vis[u]) return 0;

    int last;
    for (last = 0; (1<<last) <= dep[u]; last++){}
    last--;

    for (int j = last; j >= 0; j--)
        if (dp[u][j] != 0 && !vis[dp[u][j]]) u = dp[u][j];

    //printf("u = %d\n", u);
    return dep[st]+1-dep[u];
}

void path(int u){
    while (!vis[u])
        vis[u] = 1, u = p[u];
}

int  main(){
    int n, k;
    scanf("%d %d", &n, &k);
    k = n-k;
    for (int i = 0; i < n-1; i++){
        int a, b;
        scanf("%d %d", &a, &b);
        adj[a].pb(b);
        adj[b].pb(a);
    }

    fix(n, 0);

    for (int i = 1; i <= n; i++)
        dp[i][0] = p[i];
    for (int j = 1; (1<<j) < n; j++)
        for (int i = 1; i <= n; i++)
            if (dp[i][j-1] > 0)
                dp[i][j] = dp[dp[i][j-1]][j-1];

    vis[n] = 1, k--;
    for (int i = n-1; i >= 1; i--){
        //printf("i = %d, k = %d\n", i, k);
        int temp = dis(i);
        if (temp <= k)
            path(i), k -= temp;
        //printf("k now = %d\n", k);
    }

    for (int i = 1; i <= n; i++)
        if (!vis[i]) printf("%d ", i);
    printf("\n");
    return 0;
}


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

#define fi first
#define se second
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> ii;

const int len = 1e6+6;
int dp[len][25], dep[len], vis[len], p[len];
vector<int> adj[len];

void fix(int u, int d){
    dep[u] = d;

    dp[u][0] = p[u];
    for (int j = 1; (1<<j) <= dep[u]; j++)
        if (dp[u][j-1] > 0)
            dp[u][j] = dp[dp[u][j-1]][j-1];

    for (int j = 0; j < adj[u].size(); j++){
        int v = adj[u][j];
        if (p[u] != v){
            p[v] = u;
            fix(v, d+1);
        }
    }
}

int dis(int u){
    //printf("u = %d\n", u);
    int st = u;
    if (vis[u]) return 0;

    int last;
    for (last = 0; (1<<last) <= dep[u]; last++){}
    last--;

    for (int j = last; j >= 0; j--)
        if (dp[u][j] != 0 && !vis[dp[u][j]]) u = dp[u][j];

    //printf("u = %d\n", u);
    return dep[st]+1-dep[u];
}

void path(int u){
    while (!vis[u])
        vis[u] = 1, u = p[u];
}

int  main(){
    int n, k;
    scanf("%d %d", &n, &k);
    k = n-k;
    for (int i = 0; i < n-1; i++){
        int a, b;
        scanf("%d %d", &a, &b);
        adj[a].pb(b);
        adj[b].pb(a);
    }

    fix(n, 0);
/*
    for (int i = 1; i <= n; i++)
        dp[i][0] = p[i];
    for (int j = 1; (1<<j) < n; j++)
        for (int i = 1; i <= n; i++)
            if (dp[i][j-1] > 0)
                dp[i][j] = dp[dp[i][j-1]][j-1];
*/
    vis[n] = 1, k--;
    for (int i = n-1; i >= 1; i--){
        //printf("i = %d, k = %d\n", i, k);
        int temp = dis(i);
        if (temp <= k)
            path(i), k -= temp;
        //printf("k now = %d\n", k);
    }

    for (int i = 1; i <= n; i++)
        if (!vis[i]) printf("%d ", i);
    printf("\n");
    return 0;
}


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

#define fi first
#define se second
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> ii;

const int len = 1e6+6;
int dp[len][25], dep[len], vis[len], p[len];
vector<int> adj[len];

void fix(int u, int d){
    dep[u] = d;
    for (int j = 0; j < adj[u].size(); j++){
        int v = adj[u][j];
        if (p[u] != v){
            p[v] = u;
            fix(v, d+1);
        }
    }
}

int dis(int u){
    //printf("u = %d\n", u);
    int st = u;
    if (vis[u]) return 0;

    int last;
    for (last = 0; (1<<last) <= dep[u]; last++){}
    last--;

    for (int j = last; j >= 0; j--)
        if (!vis[dp[u][j]]) u = dp[u][j];

    //printf("u = %d\n", u);
    return dep[st]+1-dep[u];
}

void path(int u){
    while (!vis[u])
        vis[u] = 1, u = p[u];
}

int  main(){
    int n, k;
    scanf("%d %d", &n, &k);
    k = n-k;
    for (int i = 0; i < n-1; i++){
        int a, b;
        scanf("%d %d", &a, &b);
        adj[a].pb(b);
        adj[b].pb(a);
    }

    fix(n, 0);

    for (int i = 1; i <= n; i++)
        dp[i][0] = p[i];
    for (int j = 1; (1<<j) < n; j++)
        for (int i = 1; i <= n; i++)
            if (dp[i][j-1] > 0)
                dp[i][j] = dp[dp[i][j-1]][j-1];

    vis[n] = 1, k--;
    for (int i = n-1; i >= 1; i--){
        //printf("i = %d, k = %d\n", i, k);
        int temp = dis(i);
        if (temp <= k)
            path(i), k -= temp;
        //printf("k now = %d\n", k);
    }

    for (int i = 1; i <= n; i++)
        if (!vis[i]) printf("%d ", i);
    printf("\n");
    return 0;
}


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

const int N = 1e6 + 7;

int fa[N][21];
vector<int> G[N];
bool vis[N];
int dep[N];

void init()
{
    for(int i = 0;i < N;i ++)
        G[i].clear();
    memset(vis,0,sizeof(vis));
}

void dfs(int u,int f,int d)
{
    fa[u][0] = f;
    dep[u] = d;
    for(int i = 1;i <= 20;i ++)
        fa[u][i] = fa[fa[u][i - 1]][i - 1];
    for(auto v : G[u])
    {
        if(v == f)
            continue;
        dfs(v,u,d + 1);
    }
}

int go(int u)
{
    for(int i = 20;i >= 0;i --)
        if(!vis[fa[u][i]])
            u = fa[u][i];
    return u;
}

int main()
{
    ios :: sync_with_stdio(false);
    int n,k;
    while(cin >> n >> k)
    {
        init();
        for(int i = 1;i < n;i ++)
        {
            int u,v;
            cin >> u >> v;
            G[u].push_back(v);
            G[v].push_back(u);
        }
        dfs(n,n,0);
        k = n - k;
        vis[n] = 1;
        k --;
        for(int i = n - 1;i >= 1;i --)
        {
            int pre = go(i);
            if(dep[i] - dep[pre] + 1 > k)
                continue;
            int r = i;
            while(!vis[r])
            {
                vis[r] = 1;
                r = fa[r][0];
                k --;
            }
        }
        vector<int> anc;
        for(int i = 1;i <= n;i ++)
        {
            if(!vis[i])
                anc.push_back(i);
        }
        for(int i = 0;i < anc.size();i ++)
        {
            if(i)
                cout << " ";
            cout << anc[i];
        }
        cout << endl;
    }
}


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

const int N = 1e6 + 7;

int fa[N][21];
vector<int> G[N];
bool vis[N];
int dep[N];

void init()
{
    for(int i = 0;i < N;i ++)
        G[i].clear();
    memset(vis,0,sizeof(vis));
}

void dfs(int u,int f,int d)
{
    fa[u][0] = f;
    dep[u] = d;
    for(int i = 1;i <= 20;i ++)
        fa[u][i] = fa[fa[u][i - 1]][i - 1];
    for(auto v : G[u])
    {
        if(v == f)
            continue;
        dfs(v,u,d + 1);
    }
}

int go(int u)
{
    for(int i = 20;i >= 0;i --)
        if(!vis[fa[u][i]])
            u = fa[u][i];
    return u;
}

int main()
{
    int n,k;
    while(cin >> n >> k)
    {
        init();
        for(int i = 1;i < n;i ++)
        {
            int u,v;
            cin >> u >> v;
            G[u].push_back(v);
            G[v].push_back(u);
        }
        dfs(n,n,0);
        k = n - k;
        vis[n] = 1;
        k --;
        for(int i = n - 1;i >= 1;i --)
        {
            int pre = go(i);
            if(dep[i] - dep[pre] + 1 > k)
                continue;
            int r = i;
            while(!vis[r])
            {
                vis[r] = 1;
                r = fa[r][0];
                k --;
            }
        }
        vector<int> anc;
        for(int i = 1;i <= n;i ++)
        {
            if(!vis[i])
                anc.push_back(i);
        }
        for(int i = 0;i < anc.size();i ++)
        {
            if(i)
                cout << " ";
            cout << anc[i];
        }
        cout << endl;
    }
}


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

const int N = 1e6 + 7;

int fa[N][21];
vector<int> G[N];
bool vis[N];
int dep[N];

void init()
{
    for(int i = 0;i < N;i ++)
        G[i].clear();
    memset(vis,0,sizeof(vis));
}

void dfs(int u,int f,int d)
{
    fa[u][0] = f;
    dep[u] = d;
    for(int i = 1;i <= 20;i ++)
        fa[u][i] = fa[fa[u][i - 1]][i - 1];
    for(auto v : G[u])
    {
        if(v == f)
            continue;
        dfs(v,u,d + 1);
    }
}

int go(int u)
{
    for(int i = 20;i >= 0;i --)
        if(!vis[fa[u][i]])
            u = fa[u][i];
    return u;
}

int main()
{
    //ios :: sync_with_stdio(false);
    int n,k;
    while(scanf("%d%d",&n,&k) == 2)
    {
        init();
        for(int i = 1;i < n;i ++)
        {
            int u,v;
            scanf("%d%d",&u,&v);
            G[u].push_back(v);
            G[v].push_back(u);
        }
        dfs(n,n,0);
        k = n - k;
        vis[n] = 1;
        k --;
        for(int i = n - 1;i >= 1;i --)
        {
            int pre = go(i);
            if(dep[i] - dep[pre] + 1 > k)
                continue;
            int r = i;
            while(!vis[r])
            {
                vis[r] = 1;
                r = fa[r][0];
                k --;
            }
        }
        vector<int> anc;
        for(int i = 1;i <= n;i ++)
        {
            if(!vis[i])
                anc.push_back(i);
        }
        for(int i = 0;i < anc.size();i ++)
        {
            if(i)
                printf(" ");
            printf("%d",anc[i]);
        }
        printf("\n");
    }
}