#include <bits/stdc++.h>
using namespace std;
bool visited[1000000];

vector <long long> cost;
vector <long long> mustpay;
vector <long long > v[1000000];
bool listed[1000000];
long long charas, pairs, pay, nowpay, a, b, total, ntp;
long long int minimum;
queue <long long> q;

vector <long long> pairi[1000000];
void dfs(int s){
 if(visited[s]==0)
        {
             minimum=cost[s-1];
//             cout<<cost[s-1]<<endl;
            queue<int> q;
            q.push(s);
            visited[s]=1;

            while(!q.empty())
            {
                int p=q.front();

                q.pop();
                for(long long j=0; j<pairi[p].size() ;j++)
                {
                    int nd=pairi[p][j];
                    if(visited[nd]==0)
                    {
                        q.push(nd);
//                        cout<<nd<<endl;
                        visited[nd]=1;
                        minimum=min(cost[nd-1],minimum);
//                        cout<<minimum<<endl;
                    }
                }
            }
}
}
//vector <long long> pairi[10010];
int main(){
	cin>>charas;
	cin>>pairs;
	memset(listed, false, charas);

	for (long long i=1; i<=charas; i++){
		cin>>pay;
		cost.push_back(pay);
	}
	long long total=0;
	if (pairs==0){
		for (long long r=0; r<charas; r++){
			total+=cost[r];
		}
	}
	else{
		for (long long t=1; t<=pairs; t++){
			cin>>a>>b;
			if (listed[a]==false&&listed[b]==false){
				listed[a]=true;
				listed[b]=true;
				//       1            3
					pairi[b].push_back(a);
					//pair[1][0] berisi 3;
					pairi[a].push_back(b);
			}
			else{
				 if (listed[a]==false && listed[b]==true){
					int y=pairi[b][0];
					listed[a]=true;
//					cout<<y<<endl;
					pairi[y].push_back(a);
					pairi[a].push_back(b);
					pairi[b].push_back(a);
				}
				 if (listed[a]==true && listed[b]==false){
					int g=pairi[a][0];
//					cout<<g<<endl;
					pairi[g].push_back(b);
					pairi[b].push_back(a);
					pairi[a].push_back(b);
				}
			}

		}

	for (long long m=1; m<=charas; m++){
		if (visited[m]==false){
			dfs(m);
			total+=minimum;
		}

	}

	}
	cout<<total;
}


#include <bits/stdc++.h>

using namespace std;
int maxn = 111111111;
int n,m,mns;
long long res;
int a[111111];
vector<int> g[111111];
int used[111111];

void dfs(int u){
    used[u] = 1;
    mns = min(mns,a[u]);
    for(int i = 0; i < g[u].size(); i ++){
        if(!used[g[u][i]]){
            dfs(g[u][i]);
            return;
        }
    }
}

int main(){
    cin >> n >> m;
    for(int i = 1; i <= n; i ++){
        cin >> a[i];
    }
    for(int i = 0; i < m; i ++){
        int u,v;
        cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    for(int i = 1; i <= n; i ++){
        mns = maxn;
        if(!used[i]){
            dfs(i);
            res += mns;
        }
    }
    cout << res;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
int maxn = 111111111;
int n,m,mns,res;
int a[111];
vector<int> g[111];
int used[111];

void dfs(int u){
    used[u] = 1;
    mns = min(mns,a[u]);
    for(int i = 0; i < g[u].size(); i ++){
        if(!used[g[u][i]]){
            dfs(g[u][i]);
            return;
        }
    }
}

int main(){
    cin >> n >> m;
    for(int i = 1; i <= n; i ++){
        cin >> a[i];
    }
    for(int i = 0; i < m; i ++){
        int u,v;
        cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    for(int i = 1; i <= n; i ++){
        mns = maxn;
        if(!used[i]){
            dfs(i);
            res += mns;
        }
    }
    cout << res;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
const long long maxn = 1111111111;
int n,m;
__int64 res,mns;
long long a[1111111];
vector<int> g[1111111];
bool used[1111111];

void dfs(long long u){
    used[u] = 1;
    mns = min(mns,a[u]);
    for(int i = 0; i < g[u].size(); i ++){
        if(!used[g[u][i]]){
            dfs(g[u][i]);
        }
    }
}

int main(){
    cin >> n >> m;
    for(int i = 1; i <= n; i ++){
        cin >> a[i];
    }
    for(int i = 0; i < m; i ++){
        int u,v;
        cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    for(int i = 1; i <= n; i ++){
        mns = maxn;
        if(used[i] == 0)
            dfs(i);
            res += mns;
        }
    }
    cout << res;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
const long long maxn = 1111111111;
int n,m;
__int64 res,mns;
long long a[1111111];
vector<int> g[1111111];
bool used[1111111];

void dfs(long long u){
    used[u] = 1;
    mns = min(mns,a[u]);
    for(int i = 0; i < g[u].size(); i ++){
        if(!used[g[u][i]]){
            dfs(g[u][i]);
            return;
        }
    }
}

int main(){
    cin >> n >> m;
    for(int i = 1; i <= n; i ++){
        cin >> a[i];
    }
    for(int i = 0; i < m; i ++){
        int u,v;
        cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    for(int i = 1; i <= n; i ++){
        mns = maxn;
        if(!used[i]){
            dfs(i);
            res += mns;
        }
    }
    cout << res;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
long long maxn = 1111111111;
int n,m;
long long res,mns;
long long a[111111];
vector<int> g[111111];
int used[111111];

void dfs(long long u){
    used[u] = 1;
    mns = min(mns,a[u]);
    for(int i = 0; i < g[u].size(); i ++){
        if(!used[g[u][i]]){
            dfs(g[u][i]);
            return;
        }
    }
}

int main(){
    cin >> n >> m;
    for(int i = 1; i <= n; i ++){
        cin >> a[i];
    }
    for(int i = 0; i < m; i ++){
        int u,v;
        cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    for(int i = 1; i <= n; i ++){
        mns = maxn;
        if(!used[i]){
            dfs(i);
            res += mns;
        }
    }
    cout << res;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
const long long maxn = 1111111111;
int n,m;
__int64 res,mns;
long long a[111111];
vector<int> g[111111];
bool used[111111];

void dfs(long long u){
    used[u] = 1;
    mns = min(mns,a[u]);
    for(int i = 0; i < g[u].size(); i ++){
        if(!used[g[u][i]]){
            dfs(g[u][i]);
            return;
        }
    }
}

int main(){
    cin >> n >> m;
    for(int i = 1; i <= n; i ++){
        cin >> a[i];
    }
    for(int i = 0; i < m; i ++){
        int u,v;
        cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    for(int i = 1; i <= n; i ++){
        mns = maxn;
        if(!used[i]){
            dfs(i);
            res += mns;
        }
    }
    cout << res;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
long long maxn = 1111111111;
int n,m;
long long res,mns;
long long a[111111];
vector<long long> g[111111];
long long used[111111];

void dfs(long long u){
    used[u] = 1;
    mns = min(mns,a[u]);
    for(int i = 0; i < g[u].size(); i ++){
        if(!used[g[u][i]]){
            dfs(g[u][i]);
            return;
        }
    }
}

int main(){
    cin >> n >> m;
    for(int i = 1; i <= n; i ++){
        cin >> a[i];
    }
    for(int i = 0; i < m; i ++){
        int u,v;
        cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    for(int i = 1; i <= n; i ++){
        mns = maxn;
        if(!used[i]){
            dfs(i);
            res += mns;
        }
    }
    cout << res;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
const long long maxn = 1111111111;
int n,m;
__int64 res,mns;
long long a[1111111];
vector<int> g[1111111];
bool used[1111111];

void dfs(long long u){
    used[u] = 1;
    mns = min(mns,a[u]);
    for(int i = 0; i < g[u].size(); i ++){
        if(!used[g[u][i]]){
            dfs(g[u][i]);
        }
    }
}

int main(){
    cin >> n >> m;
    for(int i = 1; i <= n; i ++){
        cin >> a[i];
    }
    for(int i = 0; i < m; i ++){
        int u,v;
        cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    for(int i = 1; i <= n; i ++){
        mns = maxn;
        if(!used[i]){
            dfs(i);
            res += mns;
        }
    }
    cout << res;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
long long maxn = 111111111111;
int n,m;
long long res,mns;
long long a[111111];
vector<long long> g[111111];
long long used[111111];

void dfs(long long u){
    used[u] = 1;
    mns = min(mns,a[u]);
    for(int i = 0; i < g[u].size(); i ++){
        if(!used[g[u][i]]){
            dfs(g[u][i]);
            return;
        }
    }
}

int main(){
    cin >> n >> m;
    for(int i = 1; i <= n; i ++){
        cin >> a[i];
    }
    for(int i = 0; i < m; i ++){
        int u,v;
        cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    for(int i = 1; i <= n; i ++){
        mns = maxn;
        if(!used[i]){
            dfs(i);
            res += mns;
        }
    }
    cout << res;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll x=1000000007;
int n=100001,m=100001;

ll fun(vector<int> v[],ll p[],int s[],int x)
{
   int i,j,k;

   ll c=0;

   if(p[x]!=-1)
   {
      return p[x];
   }

   for(i=0;i<v[x].size();i++)
   {
      c=c+fun(v,p,s,v[x][i]);
   }

   p[x]=s[x]+c;

   return p[x];

}

void dfs(vector<int> v[],bool vis[],int x)
{
  int i,j,k;

   if(vis[x]==1)
    return;

   vis[x]=1;

   for(i=0;i<v[x].size();i++)
   {
     dfs(v,vis,v[x][i]);
   }

   return;

}

int main()
{
   int i,j,k,a,b,c,l,t,w;

   cin>>n>>m;

   int s[n+1];

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

   vector<int> v[n+1];

   for(i=0;i<=m-1;i++)
   {
      cin>>a>>b;
      v[a].push_back(b);

   }

   ll p[n+1];

   for(i=1;i<=n;i++)
   {
     p[i]=-1;
   }

   for(i=1;i<=n;i++)
   {
      a=fun(v,p,s,i);
   }

   pair<ll,int> d[n+1];

   d[0].first=0;
   d[0].second=0;

   for(i=1;i<=n;i++)
   {
     //cout<<p[i]<<" ";
     d[i]=make_pair(p[i],i);
   }

   sort(d,d+n+1);

   c=0;
   bool vis[n+1];
   memset(vis,0,sizeof vis);

   for(i=n;i>=1;i--)
   {
      if(vis[d[i].second]==0)
        {
          c=c+s[d[i].second];
          dfs(v,vis,d[i].second);
        }

   }

   cout<<c<<"\n";

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll x=1000000007;
int n,m;

ll fun(vector<int> v[n+1],ll p[],int s[],int x)
{
   int i,j,k;

   ll c=0;

   if(p[x]!=-1)
   {
      return p[x];
   }

   for(i=0;i<v[x].size();i++)
   {
      c=c+fun(v,p,s,v[x][i]);
   }

   p[x]=s[x]+c;

   return p[x];

}

void dfs(vector<int> v[n+1],bool vis[],int x)
{
  int i,j,k;

   if(vis[x]==1)
    return;

   vis[x]=1;

   for(i=0;i<v[x].size();i++)
   {
     dfs(v,vis,v[x][i]);
   }

   return;

}

int main()
{
   int i,j,k,a,b,c,l,t,w;

   cin>>n>>m;

   int s[n+1];

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

   vector<int> v[n+1];

   for(i=0;i<=m-1;i++)
   {
      cin>>a>>b;
      v[a].push_back(b);

   }

   ll p[n+1];

   for(i=1;i<=n;i++)
   {
     p[i]=-1;
   }

  // exit(0);
   for(i=1;i<=n;i++)
   {
      a=fun(v,p,s,i);
   }

   pair<int,ll> d[n+1];

   for(i=1;i<=n;i++)
   {
     //cout<<p[i]<<" ";
     d[i]=make_pair(i,p[i]);
   }

   sort(d,d+n+1);

   c=0;
   bool vis[n+1];
   memset(vis,0,sizeof vis);

   for(i=1;i<=n;i++)
   {
      if(vis[i]==0)
       c=c+s[i];

      dfs(v,vis,d[i].first);
   }

   cout<<c<<"\n";

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll x=1000000007;

int main()
{
   ll i,j,k,a,b,c,d,m,n,l,t,w;

   cin>>n>>m;

   int s[n+1];

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

   bool p[n+1];
   memset(p,0,sizeof p);

   for(i=0;i<=m-1;i++)
   {
     cin>>a>>b;
     p[b]=1;
   }

   c=0;
   for(i=1;i<=n;i++)
   {
      if(p[i]==0)
        c=c+s[i];
   }

   cout<<c<<"\n";

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll x=1000000007;
int n=100001,m=100001;

ll fun(vector<int> v[],ll p[],int s[],int x)
{
   int i,j,k;

   ll c=0;

   if(p[x]!=-1)
   {
      return p[x];
   }

   for(i=0;i<v[x].size();i++)
   {
      c=c+fun(v,p,s,v[x][i]);
   }

   p[x]=s[x]+c;

   return p[x];

}

void dfs(vector<int> v[],bool vis[],int x)
{
  int i,j,k;

   if(vis[x]==1)
    return;

   vis[x]=1;

   for(i=0;i<v[x].size();i++)
   {
     dfs(v,vis,v[x][i]);
   }

   return;

}

int main()
{
   int i,j,k,a,b,c,l,t,w;

   cin>>n>>m;

   int s[n+1];

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

   vector<int> v[n+1];

   for(i=0;i<=m-1;i++)
   {
      cin>>a>>b;
      v[a].push_back(b);

   }

   ll p[n+1];

   for(i=1;i<=n;i++)
   {
     p[i]=-1;
   }

   for(i=1;i<=n;i++)
   {
      a=fun(v,p,s,i);
   }

   pair<ll,int> d[n+1];

   for(i=1;i<=n;i++)
   {
     d[i]=make_pair(p[i],i);
   }

   sort(d,d+n+1);

   c=0;
   bool vis[n+1];
   memset(vis,0,sizeof vis);

   for(i=1;i<=n;i++)
   {
      if(vis[i]==0)
       c=c+s[i];

      dfs(v,vis,d[i].second);

   }

   cout<<c<<"\n";

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll x=1000000007;
int n=100001,m=100001;

ll fun(vector<int> v[],ll p[],int s[],int x)
{
   int i,j,k;

   ll c=0;

   if(p[x]!=-1)
   {
      return p[x];
   }

   for(i=0;i<v[x].size();i++)
   {
      c=c+fun(v,p,s,v[x][i]);
   }

   p[x]=s[x]+c;

   return p[x];

}

void dfs(vector<int> v[],bool vis[],int x)
{
  int i,j,k;

   if(vis[x]==1)
    return;

   vis[x]=1;

   for(i=0;i<v[x].size();i++)
   {
     dfs(v,vis,v[x][i]);
   }

   return;

}

int main()
{
   int i,j,k,a,b,l,t,w;

   cin>>n>>m;

   int s[n+1];

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

   vector<int> v[n+1];

   for(i=0;i<=m-1;i++)
   {
      cin>>a>>b;
      v[a].push_back(b);

   }

   ll p[n+1];

   for(i=1;i<=n;i++)
   {
     p[i]=-1;
   }

   for(i=1;i<=n;i++)
   {
      a=fun(v,p,s,i);
   }

   pair<ll,int> d[n+1];

   d[0].first=0;
   d[0].second=0;

   for(i=1;i<=n;i++)
   {
     //cout<<p[i]<<" ";
     d[i]=make_pair(p[i],i);
   }

   sort(d,d+n+1);

   ll c=0;
   bool vis[n+1];
   memset(vis,0,sizeof vis);

   for(i=n;i>=1;i--)
   {
      if(vis[d[i].second]==0)
        {
          c=c+s[d[i].second];
          dfs(v,vis,d[i].second);
        }

   }

   cout<<c<<"\n";

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll x=1000000007;
int n=100001,m=100001;

int fun(vector<int> v[],int p[],int s[],int x)
{
   int i,j,k,l=INT_MAX;

   if(p[x]==1)
   {
      return l;
   }

   p[x]=1;

   for(i=0;i<v[x].size();i++)
   {
      if(p[v[x][i]]==0)
         l=min(l,fun(v,p,s,v[x][i]));
   }

   return l=min(l,s[x]);

}

int main()
{
   int i,j,k,a,b,l,t,w;

   cin>>n>>m;

   int s[n+1];

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

   vector<int> v[n+1];

   for(i=0;i<=m-1;i++)
   {
      cin>>a>>b;
      v[a].push_back(b);
      v[b].push_back(a);

   }

   int p[n+1];
   memset(p,0,sizeof p);

   vector<int> u;

   for(i=1;i<=n;i++)
   {
      if(p[i]==0)
      {
        u.push_back(fun(v,p,s,i));
      }

   }

   ll c=0;
   for(i=0;i<u.size();i++)
   {
     //cout<<u[i]<<" ";
     c=c+u[i];
   }

   cout<<c<<"\n";

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll x=1000000007;
int n=100001,m=100001;

ll fun(vector<int> v[],ll p[],int s[],int x)
{
   int i,j,k;

   ll c=0;

   if(p[x]!=-1)
   {
      return p[x];
   }

   for(i=0;i<v[x].size();i++)
   {
      c=c+fun(v,p,s,v[x][i]);
   }

   p[x]=s[x]+c;

   return p[x];

}

void dfs(vector<int> v[],bool vis[],int x)
{
  int i,j,k;

   if(vis[x]==1)
    return;

   vis[x]=1;

   for(i=0;i<v[x].size();i++)
   {
     dfs(v,vis,v[x][i]);
   }

   return;

}

int main()
{
   int i,j,k,a,b,c,l,t,w;

   cin>>n>>m;

   int s[n+1];

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

   vector<int> v[n+1];

   for(i=0;i<=m-1;i++)
   {
      cin>>a>>b;
      v[a].push_back(b);

   }

   ll p[n+1];

   for(i=1;i<=n;i++)
   {
     p[i]=-1;
   }

   for(i=1;i<=n;i++)
   {
      a=fun(v,p,s,i);
   }

   pair<int,ll> d[n+1];

   for(i=1;i<=n;i++)
   {
     d[i]=make_pair(i,p[i]);
   }

   sort(d,d+n+1);

   c=0;
   bool vis[n+1];
   memset(vis,0,sizeof vis);

   for(i=1;i<=n;i++)
   {
      if(vis[i]==0)
       c=c+s[i];

      dfs(v,vis,d[i].first);
   }

   cout<<c<<"\n";

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll x=1000000007;
int n=100001,m=100001;

ll fun(vector<int> v[n+1],ll p[],int s[],int x)
{
   int i,j,k;

   ll c=0;

   if(p[x]!=-1)
   {
      return p[x];
   }

   for(i=0;i<v[x].size();i++)
   {
      c=c+fun(v,p,s,v[x][i]);
   }

   p[x]=s[x]+c;

   return p[x];

}

void dfs(vector<int> v[n+1],bool vis[],int x)
{
  int i,j,k;

   if(vis[x]==1)
    return;

   vis[x]=1;

   for(i=0;i<v[x].size();i++)
   {
     dfs(v,vis,v[x][i]);
   }

   return;

}

int main()
{
   int i,j,k,a,b,c,l,t,w;

   cin>>n>>m;

   int s[n+1];

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

   vector<int> v[n+1];

   for(i=0;i<=m-1;i++)
   {
      cin>>a>>b;
      v[a].push_back(b);

   }

   ll p[n+1];

   for(i=1;i<=n;i++)
   {
     p[i]=-1;
   }

  // exit(0);
   for(i=1;i<=n;i++)
   {
      a=fun(v,p,s,i);
   }

   pair<int,ll> d[n+1];

   for(i=1;i<=n;i++)
   {
     //cout<<p[i]<<" ";
     d[i]=make_pair(i,p[i]);
   }

   sort(d,d+n+1);

   c=0;
   bool vis[n+1];
   memset(vis,0,sizeof vis);

   for(i=1;i<=n;i++)
   {
      if(vis[i]==0)
       c=c+s[i];

      dfs(v,vis,d[i].first);
   }

   cout<<c<<"\n";

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll x=1000000007;

int main()
{
   ll i,j,k,a,b,c,d,m,n,l,t,w;

   cin>>n>>m;

   ll s[n+1];

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

   bool p[n+1];
   memset(p,0,sizeof p);

   for(i=0;i<=m-1;i++)
   {
     cin>>a>>b;
     p[b]=1;
   }

   c=0;
   for(i=1;i<=n;i++)
   {
      if(p[i]==0)
        c=c+s[i];
   }

   cout<<c<<"\n";

}


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

void dfs(vector<int> v[],int arr[], int visited[], int i, int &c)
{
        visited[i]=1;

        c=min(c,arr[i]);

        for(int j=0;j<v[i].size();j++)
        {
           if(visited[v[i][j]]==0)
             dfs(v,arr,visited,v[i][j],c);
        }

}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll n,m;
    cin>>n>>m;

    int arr[100005];

    for(int i=1;i<=n;i++)
    cin>>arr[i];

    vector<int> v[100005];

    for(int i=0;i<m;i++)
    {
        int a,b;
        cin>>a>>b;

        v[a].push_back(b);
        v[b].push_back(a);

    }

    int ans=0;
    int visited[100005]={0};

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

        if(v[i].size()==0 && visited[i]==0)
        {
            visited[i]=1;
            ans+=arr[i];
        }

        else
        if(visited[i]==0)
        {
            dfs(v,arr,visited,i,c);
              ans+=c;
        }

    }

    cout<<ans;

}


using namespace std;
#include <bits/stdc++.h>
#define FIO ios_base::sync_with_stdio(false)
#define ll long long
#define f first
#define s second

bool f[100005] = {0};
map <int, int> M;
int A[100005];
int B[100005];
int main(){ FIO;
	int n,q; cin >> n >> q;
	for (int i=1; i<=n; ++i){
		cin >> B[i];
	}
	for (int i=1; i<=q; ++i){
		int b; cin >> A[i] >> b;
		M[A[i]] = b;
	}
	int ans = 0;
	for (int i=1; i<=q; ++i){
		int x = A[i], mi = B[A[i]], im = A[i];
		while (M[x] && M[x] != A[i]){
			if (f[M[x]]) break;
			if (B[M[x]] < mi){
				mi = B[M[x]];
				im = M[x];
			}
			f[M[x]] = true;
			x = M[x];
		}
		if (im != A[i]){
			f[A[i]] = true;
			ans += mi;
		}
	}
	for (int i = 1; i <= n; ++i){
		if (!f[i]) ans += B[i];
	}
	cout << ans;
return 0;}


using namespace std;
#include <bits/stdc++.h>
#define FIO ios_base::sync_with_stdio(false)
#define ll long long
#define f first
#define s second

bool f[100005] = {0};
map <int, int> M;
int A[100005];
int B[100005];
int main(){ FIO;
	int n,q; cin >> n >> q;
	for (int i=1; i<=n; ++i){
		cin >> B[i];
	}
	for (int i=1; i<=q; ++i){
		int b; cin >> A[i] >> b;
		M[A[i]] = b;
	}
	int ans = 0;
	for (int i=1; i<=q; ++i){
		int x = A[i], mi = B[A[i]], im = A[i];
		while (M[x]){
			if (f[M[x]]){
				f[x] = true;
				break;
			}
			if (B[M[x]] < mi){
				mi = B[M[x]];
				im = M[x];
			}
			f[M[x]] = true;
			x = M[x];

		}
		if (im != A[i]){
			f[A[i]] = true;
			ans += mi;
		}
	}
	for (int i = 1; i <= n; ++i){
		if (!f[i]) {
			ans += B[i];
		}
	}
	cout << ans;
/*
5 4
2 5 3 1 8
1 4
4 5
5 3
3 1
*/
return 0;}


using namespace std;
#include <bits/stdc++.h>
#define FIO ios_base::sync_with_stdio(false)
#define ll long long
#define f first
#define s second

bool f[100005] = {0};
map <int, int> M;
int A[100005];
int B[100005];
int main(){ FIO;
	int n,q; cin >> n >> q;
	for (int i=1; i<=n; ++i){
		cin >> B[i];
	}
	for (int i=1; i<=q; ++i){
		int b; cin >> A[i] >> b;
		M[A[i]] = b;
	}
	long long ans = 0;
	for (int i=1; i<=q; ++i){
		int x = A[i], mi = B[A[i]], im = A[i];
		while (M[x]){
			if (f[M[x]]){
				f[x] = true;
				break;
			}
			if (B[M[x]] < mi){
				mi = B[M[x]];
				im = M[x];
			}
			f[M[x]] = true;
			x = M[x];

		}
		if (im != A[i]){
			f[A[i]] = true;
			ans += mi;
		}
	}
	for (int i = 1; i <= n; ++i){
		if (!f[i]) {
			ans += B[i];
		}
	}
	cout << ans;
/*
5 4
2 5 3 1 8
1 4
4 5
5 3
3 1
*/
return 0;}


using namespace std;
#include <bits/stdc++.h>
#define FIO ios_base::sync_with_stdio(0); cin.tie(NULL);
#define ll long long

int D[100005], C[100005];
pair <int,int> A[100005];
int findR(int x){
	return D[x] < 0 ? x : findR(D[x]);
}
void merge(int x, int y){
	int u = findR(x), v = findR(y);
	if (u == v) return;
	if (D[u] < D[v]) swap(u,v);
	D[u] += D[v];
	D[v] = u;
	return;
}

int main(){ FIO;
	int n, m; cin >> n >> m;
	for (int i=1; i<=n; ++i){
		cin >> A[i].first;
		A[i].second = i;
		D[i] = -1;
		C[i] = 0;
	}
	sort (A+1,A+n+1);
	for (int i=1; i<=m; ++i){
		int x, y; cin >> x >> y;
		merge(x,y);
	}
	ll ans = 0;
	for (int i=1; i<=n; ++i){
		int x = findR(A[i].second);
		if (!C[x]){
			C[x] = 1;
			ans += A[i].first;
		}
	}
	cout << ans;
return 0;}


using namespace std;
#include <bits/stdc++.h>
#define FIO ios_base::sync_with_stdio(0); cin.tie(NULL);
#define ll long long

int A[100005], D[100005], C[100005];
int findR(int x){
	return D[x] < 0 ? x : findR(D[x]);
}
void merge(int x, int y){
	int u = findR(x), v = findR(y);
	if (u == v) return;
	if (D[u] < D[v]) swap(u,v);
	D[v] += D[u];
	if (A[u] > A[v]) A[u] = A[v];
	D[v] = u;
}

int main(){ FIO;
	int n, m; cin >> n >> m;
	for (int i=1; i<=n; ++i){
		cin >> A[i];
		D[i] = -1;
		C[i] = 0;
	}
	for (int i=1; i<=m; ++i){
		int x, y; cin >> x >> y;
		merge(x,y);
	}
	ll ans = 0;
	for (int i=1; i<=n; ++i){
		int x = findR(i);
		if (!C[x]){
			C[x] = 1;
			ans += A[x];
		}
	}
	cout << ans;
return 0;}


using namespace std;
#include <bits/stdc++.h>
#define FIO ios_base::sync_with_stdio(false)
#define ll long long
#define f first
#define s second

bool f[100005] = {0};
map <int, int> M;
int A[100005];
int B[100005];
int main(){ FIO;
	int n,q; cin >> n >> q;
	for (int i=1; i<=n; ++i){
		cin >> B[i];
	}
	for (int i=1; i<=q; ++i){
		int b; cin >> A[i] >> b;
		M[A[i]] = b;
	}
	for (int i=1; i<=q; ++i){
		int x = A[i];
		while (M[x] && M[x] != A[i]){
			if (f[M[x]]) break;
			f[M[x]] = true;
			x = M[x];
		}
	}
	int ans = 0;
	for (int i = 1; i <= n; ++i){
		if (!f[i]) ans += B[i];
	}
	cout << ans;
return 0;}


using namespace std;
#include <bits/stdc++.h>
#define FIO ios_base::sync_with_stdio(0); cin.tie(NULL);
#define ll long long

int D[100005], C[100005];
pair <int,int> A[100005];
int findR(int x){
	return D[x] < 0 ? x : findR(D[x]);
}
void merge(int x, int y){
	int u = findR(x), v = findR(y);
	if (u == v) return;
	if (D[u] < D[v]) swap(u,v);
	D[v] = u;
	return;
}

int main(){ FIO;
	int n, m; cin >> n >> m;
	for (int i=1; i<=n; ++i){
		cin >> A[i].first;
		A[i].second = i;
		D[i] = -1;
		C[i] = 0;
	}
	sort (A+1,A+n+1);
	for (int i=1; i<=m; ++i){
		int x, y; cin >> x >> y;
		merge(x,y);
	}
	ll ans = 0;
	for (int i=1; i<=n; ++i){
		int x = findR(A[i].second);
		if (!C[x]){
			C[x] = 1;
			ans += A[i].first;
		}
	}
	cout << ans;
return 0;}


using namespace std;
#include <bits/stdc++.h>
#define FIO ios_base::sync_with_stdio(0); cin.tie(NULL);
#define ll long long

int A[100005], D[100005], C[100005];

int findR(int x){
	return D[x] < 0 ? x : findR(D[x]);
}

void merge(int x, int y){
	int u = findR(x), v = findR(y);
	if (u == v) return;
	if (A[u] > A[v]) swap(u,v);
	D[v] = u;
	return;
}

int main(){ FIO;
	int n, m; cin >> n >> m;
	for (int i=1; i<=n; ++i){
		cin >> A[i];
		D[i] = -1;
		C[i] = 0;
	}
	for (int i=1; i<=m; ++i){
		int x, y; cin >> x >> y;
		merge(x,y);
	}
	ll ans = 0;
	for (int i=1; i<=n; ++i){
		int x = findR(i);
		if (!C[x]){
			C[x] = 1;
			ans += 1LL*A[x];
		}
	}
	cout << ans;
return 0;}


using namespace std;
#include <bits/stdc++.h>
#define FIO ios_base::sync_with_stdio(0); cin.tie(NULL);
#define ll long long

int A[100005], D[100005], C[100005];
int findR(int x){
	return D[x] < 0 ? x : findR(D[x]);
}
void merge(int x, int y){
	int u = findR(x), v = findR(y);
	if (u == v) return;
	if (D[u] < D[v]) swap(u,v);
	D[v] += D[u];
	if (A[u] > A[v]) A[u] = A[v];
	D[v] = u;
}

int main(){ FIO;
	int n, m;
	scanf("%d %d", &n, &m);
	for (int i=1; i<=n; ++i){
		scanf("%d",&A[i]);
		D[i] = -1;
		C[i] = 0;
	}
	int x,y;
	for (int i=1; i<=m; ++i){
		scanf("%d %d", &x, &y);
		merge(x,y);
	}
	ll ans = 0;
	for (int i=1; i<=n; ++i){
		int x = findR(i);
		if (!C[x]){
			C[x] = 1;
			ans += A[x];
		}
	}
	printf("%lld",ans);
return 0;}


using namespace std;
#include <bits/stdc++.h>
#define FIO ios_base::sync_with_stdio(0); cin.tie(NULL);
#define ll long long

int A[100005], D[100005], C[100005];
int findR(int x){
	return D[x] == x ? x : D[x] = findR(D[x]);
}
void merge(int x, int y){
	int u = findR(x), v = findR(y);
	if (u == v) return;
	if (A[v] > A[u]){
		A[v] = A[u];
		D[v] = u;
	} else {
		A[u] = A[v];
		D[u] = v;
	}
}

int main(){ FIO;
	int n, m;
	scanf("%d %d", &n, &m);
	for (int i=1; i<=n; ++i){
		scanf("%d",&A[i]);
		D[i] = i;
		C[i] = 0;
	}
	int x,y;
	for (int i=1; i<=m; ++i){
		scanf("%d %d", &x, &y);
		merge(x,y);
	}
	ll ans = 0;
	for (int i=1; i<=n; ++i){
		int x = findR(i);
		if (!C[x]){
			C[x] = 1;
			ans += A[x];
		}
	}
	printf("%lld",ans);
return 0;}


using namespace std;
#include <bits/stdc++.h>
#define FIO ios_base::sync_with_stdio(0); cin.tie(NULL);
#define ll long long

int D[100005], C[100005];
pair <int,int> A[100005];
int findR(int x){
	return D[x] < 0 ? x : findR(D[x]);
}
void merge(int x, int y){
	int u = findR(x), v = findR(y);
	if (u == v) return;
	if (D[u] > D[v]) swap(u,v);
//	D[v] += D[u];
	D[u] = v;
	return;
}

int main(){ FIO;
	int n, m; cin >> n >> m;
	for (int i=1; i<=n; ++i){
		cin >> A[i].first;
		A[i].second = i;
		D[i] = -1;
		C[i] = 0;
	}
	sort (A+1,A+n+1);
	for (int i=1; i<=m; ++i){
		int x, y; cin >> x >> y;
		merge(x,y);
	}
	ll ans = 0;
	for (int i=1; i<=n; ++i){
		int x = findR(A[i].second);
		if (!C[x]){
			C[x] = 1;
			ans += A[i].first;
		}
	}
	cout << ans;
return 0;}


using namespace std;
#include <bits/stdc++.h>
#define FIO ios_base::sync_with_stdio(false)
#define ll long long
#define f first
#define s second

bool f[100005] = {0};
map <int, int> M;
int A[100005];
int B[100005];
int main(){ FIO;
	int n,q; cin >> n >> q;
	for (int i=1; i<=n; ++i){
		cin >> B[i];
	}
	for (int i=1; i<=q; ++i){
		int b; cin >> A[i] >> b;
		M[A[i]] = b;
	}
	int ans = 0;
	for (int i=1; i<=q; ++i){
		int x = A[i], mi = B[i], im = i;
		while (M[x] && M[x] != A[i]){
			if (f[M[x]]) break;
			if (B[M[x]] < mi){
				mi = B[M[x]];
				im = M[x];
			}
			f[M[x]] = true;
			x = M[x];
		}
		if (im != i){
			f[im] = true;
			ans += mi;
		}
	}
	for (int i = 1; i <= n; ++i){
		if (!f[i]) ans += B[i];
	}
	cout << ans;
return 0;}


using namespace std;
#include <bits/stdc++.h>
#define FIO ios_base::sync_with_stdio(0); cin.tie(NULL);
#define ll long long

int A[100005], D[100005], C[100005];

int findR(int x){
	return D[x] < 0 ? x : findR(D[x]);
}
int findM(int x, int &m){
	m = min(m,A[x]);
	if (D[x] < 0){
		return x;
	}
	return findM(D[x],m);
}
void merge(int x, int y){
	int u = findR(x), v = findR(y);
	if (u == v) return;
	if (D[u] < D[v]) swap(u,v);
	D[v] = u;
	return;
}

int main(){ FIO;
	int n, m; cin >> n >> m;
	for (int i=1; i<=n; ++i){
		cin >> A[i];
		D[i] = -1;
		C[i] = 0;
	}
	for (int i=1; i<=m; ++i){
		int x, y; cin >> x >> y;
		merge(x,y);
	}
	ll ans = 0;
	for (int i=1; i<=n; ++i){
		int mi = INT_MAX;
		int x = findM(i,mi);
		if (!C[x]){
			C[x] = 1;
			ans += mi;
		}
	}
	cout << ans;
return 0;}


using namespace std;
#include <bits/stdc++.h>
#define FIO ios_base::sync_with_stdio(0); cin.tie(NULL);
#define ll long long

int D[100005], C[100005];
pair <int,int> A[100005];
int findR(int x){
	return D[x] < 0 ? x : findR(D[x]);
}
void merge(int x, int y){
	int u = findR(x), v = findR(y);
	if (u == v) return;
	if (D[u] < D[v]) swap(u,v);
	D[v] += D[u];
	D[v] = u;
	return;
}

int main(){ FIO;
	int n, m; cin >> n >> m;
	for (int i=1; i<=n; ++i){
		cin >> A[i].first;
		A[i].second = i;
		D[i] = -1;
		C[i] = 0;
	}
	sort (A+1,A+n+1);
	for (int i=1; i<=m; ++i){
		int x, y; cin >> x >> y;
		merge(x,y);
	}
	ll ans = 0;
	for (int i=1; i<=n; ++i){
		int x = findR(A[i].second);
		if (!C[x]){
			C[x] = 1;
			ans += A[i].first;
		}
	}
	cout << ans;
return 0;}


using namespace std;
#include <bits/stdc++.h>
#define FIO ios_base::sync_with_stdio(0); cin.tie(NULL);
#define ll long long

int A[100005], D[100005], C[100005];
int findR(int x){
	return D[x] == x ? x : findR(D[x]);
}
void merge(int x, int y){
	int u = findR(x), v = findR(y);
	if (u == v) return;
	if (A[v] > A[u]){
		A[v] = A[u];
		D[v] = u;
	} else {
		A[u] = A[v];
		D[u] = v;
	}
}

int main(){ FIO;
	int n, m;
	scanf("%d %d", &n, &m);
	for (int i=1; i<=n; ++i){
		scanf("%d",&A[i]);
		D[i] = i;
		C[i] = 0;
	}
	int x,y;
	for (int i=1; i<=m; ++i){
		scanf("%d %d", &x, &y);
		merge(x,y);
	}
	ll ans = 0;
	for (int i=1; i<=n; ++i){
		int x = findR(i);
		if (!C[x]){
			C[x] = 1;
			ans += A[x];
		}
	}
	printf("%lld",ans);
return 0;}


using namespace std;
#include <bits/stdc++.h>
#define FIO ios_base::sync_with_stdio(0); cin.tie(NULL);
#define ll long long

int D[100005], C[100005];
pair <int,int> A[100005];
int findR(int x){
	return D[x] < 0 ? x : findR(D[x]);
}
void merge(int x, int y){
	int u = findR(x), v = findR(y);
	if (u == v) return;
	if (D[u] > D[v]) swap(u,v);
	D[v] += D[u];
	D[u] = v;
	return;
}

int main(){ FIO;
	int n, m; cin >> n >> m;
	for (int i=1; i<=n; ++i){
		cin >> A[i].first;
		A[i].second = i;
		D[i] = -1;
		C[i] = 0;
	}
	sort (A+1,A+n+1);
	for (int i=1; i<=m; ++i){
		int x, y; cin >> x >> y;
		merge(x,y);
	}
	ll ans = 0;
	for (int i=1; i<=n; ++i){
		int x = findR(A[i].second);
		if (!C[x]){
			C[x] = 1;
			ans += A[i].first;
		}
	}
	cout << ans;
return 0;}


using namespace std;
#include <bits/stdc++.h>
#define FIO ios_base::sync_with_stdio(false)
#define ll long long
#define f first
#define s second

bool f[100005] = {0};
map <int, int> M;
int A[100005];
int B[100005];
int main(){ FIO;
	int n,q; cin >> n >> q;
	for (int i=1; i<=n; ++i){
		cin >> B[i];
	}
	for (int i=1; i<=q; ++i){
		int b; cin >> A[i] >> b;
		M[A[i]] = b;
	}
	for (int i=1; i<=q; ++i){
		int x = A[i];
		while (M[x] && M[x] != A[i]){
			f[M[x]] = true;
			x = M[x];
		}
	}
	int ans = 0;
	for (int i = 1; i <= n; ++i){
		if (!f[i]) ans += B[i];
	}
	cout << ans;
return 0;}


#include<bits/stdc++.h>

using namespace std;

#define ll long long

vector<int> mat[100005];
bool visited[100005];
int cost [100005];

ll tot = 0;

int dfs(int check)
{
    if (visited[check]) return 0;
    visited[check] = true;
    for (int i = 0; i < mat[check].size(); i++)
    {
        if (mat[check][i]) dfs(mat[check][i]);
    }

    return 0;
}

int main(int argc, char const *argv[])
{
    int n,m;

    cin >> n >> m;

    for (int i = 1; i <= n; i++) cin >> cost[i];
    for (int i = 1; i <= n; i++) visited[i] = false;
    // for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) mat[i][j] = 0;

    for (int i = 1; i <= m; i++)
    {
        int a,b;
        cin >> a >> b;
        mat[a].push_back(b);
    }

    for ( int i = 1; i <= n; i++)
    {
        if (!visited[i])
        {
            int kk = dfs(i);
            tot += cost[i];
        }
    }

    cout << tot;

    /* code */
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define ll long long

vector<int> mat[100005];
bool visited[100005];
int cost [100005];

ll tot = 0;

int dfs(int check)
{
    if (visited[check]) return 1e9+2;
    visited[check] = true;
    int mc = 1e9+2;

    if (mat[check].size() == 0)
    {
        // cout << check << " here\n";
        return cost[check];
    }

    for (int i = 0; i < mat[check].size(); i++)
    {
        if (mat[check][i])
        {
            mc = min( dfs(mat[check][i]), cost[check] );
            // cout << mc << " " << check << "heres\n";

        }
    }

    return mc;
}

int main(int argc, char const *argv[])
{
    int n,m;

    cin >> n >> m;

    for (int i = 1; i <= n; i++) cin >> cost[i];
    for (int i = 1; i <= n; i++) visited[i] = false;
    // for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) mat[i][j] = 0;

    for (int i = 1; i <= m; i++)
    {
        int a,b;
        cin >> a >> b;
        mat[a].push_back(b);
        mat[b].push_back(a);
    }

    for ( int i = 1; i <= n; i++)
    {
        if (!visited[i])
        {
            int kk = dfs(i);
            tot += kk;
        }
    }

    cout << tot;

    /* code */
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define ll long long

vector<int> mat[100005];
bool visited[100005];
int cost [100005];

vector<int> cc ;

ll tot = 0;

void dfs(int check)
{
    if (visited[check]) return ;
    visited[check] = true;

    cc.push_back(cost[check]);

    for (int i = 0; i < mat[check].size(); i++)
    {
        if (mat[check][i])
        {
            dfs(mat[check][i]);
        }
    }

    return ;
}

int main(int argc, char const *argv[])
{
    int n,m;

    cin >> n >> m;

    for (int i = 1; i <= n; i++) cin >> cost[i];
    for (int i = 1; i <= n; i++) visited[i] = false;
    // for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) mat[i][j] = 0;

    for (int i = 1; i <= m; i++)
    {
        int a,b;
        cin >> a >> b;
        mat[a].push_back(b);
    }

    for ( int i = 1; i <= n; i++)
    {
        if (!visited[i])
        {
            dfs(i);
            tot += *min_element(cc.begin(),cc.end());
            cc.clear();
        }
    }

    cout << tot;

    /* code */
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define ll long long

vector<int> mat[100005];
bool visited[100005];
int cost [100005];

ll tot = 0;

int dfs(int check,int n)
{
    if (visited[check]) return -1;
    visited[check] = true;
    for (int i = 0; i < mat[check].size(); i++)
    {
        if (mat[check][i]) dfs(mat[check][i],n);
    }

    return 0;
}

int main(int argc, char const *argv[])
{
    int n,m;

    cin >> n >> m;

    for (int i = 1; i <= n; i++) cin >> cost[i];
    for (int i = 1; i <= n; i++) visited[i] = false;
    // for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) mat[i][j] = 0;

    for (int i = 1; i <= m; i++)
    {
        int a,b;
        cin >> a >> b;
        mat[a].push_back(b);
    }

    for ( int i = 1; i <= n; i++)
    {
        int kk = dfs(i,n);
        if (kk != -1)
        {
            tot += cost[i];
        }
    }

    cout << tot;

    /* code */
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

vector<int> mat[100005];
bool visited[100005];
int cost [100005];

long tot = 0;

int dfs(int check,int n)
{
    if (visited[check]) return -1;
    visited[check] = true;
    for (int i = 0; i < mat[check].size(); i++)
    {
        if (mat[check][i]) dfs(mat[check][i],n);
    }

    return 0;
}

int main(int argc, char const *argv[])
{
    int n,m;

    cin >> n >> m;

    for (int i = 1; i <= n; i++) cin >> cost[i];
    for (int i = 1; i <= n; i++) visited[i] = false;
    // for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) mat[i][j] = 0;

    for (int i = 1; i <= m; i++)
    {
        int a,b;
        cin >> a >> b;
        mat[a].push_back(b);
    }

    for ( int i = 1; i <= n; i++)
    {
        int kk = dfs(i,n);
        if (kk != -1)
        {
            tot += cost[i];
        }
    }

    cout << tot;

    /* code */
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

int mat[10005][10005];
bool visited[100005];
int cost [100005];

long tot = 0;

int dfs(int check,int n)
{
    if (visited[check]) return -1;
    visited[check] = true;
    for (int i = 1; i <= n; i++)
    {
        if (mat[check][i]) dfs(i,n);
    }

    return 0;
}

int main(int argc, char const *argv[])
{
    int n,m;

    cin >> n >> m;

    for (int i = 1; i <= n; i++) cin >> cost[i];
    for (int i = 1; i <= n; i++) visited[i] = false;
    for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) mat[i][j] = 0;

    for (int i = 1; i <= m; i++)
    {
        int a,b;
        cin >> a >> b;
        mat[a][b] = 1;
    }

    for ( int i = 1; i <= n; i++)
    {
        int kk = dfs(i,n);
        if (kk != -1)
        {
            tot += cost[i];
        }
    }

    cout << tot;

    /* code */
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

int mat[105][105];
bool visited[100005];
int cost [100005];

long tot = 0;

int dfs(int check,int n)
{
    if (visited[check]) return -1;
    visited[check] = true;
    for (int i = 1; i <= n; i++)
    {
        if (mat[check][i]) dfs(i,n);
    }

    return 0;
}

int main(int argc, char const *argv[])
{
    int n,m;

    cin >> n >> m;

    for (int i = 1; i <= n; i++) cin >> cost[i];
    for (int i = 1; i <= n; i++) visited[i] = false;
    for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) mat[i][j] = 0;

    for (int i = 1; i <= m; i++)
    {
        int a,b;
        cin >> a >> b;
        mat[a][b] = 1;
    }

    for ( int i = 1; i <= n; i++)
    {
        int kk = dfs(i,n);
        if (kk != -1)
        {
            tot += cost[i];
        }
    }

    cout << tot;

    /* code */
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define ll long long

vector<int> mat[100005];
bool visited[100005];
int cost [100005];

ll tot = 0;

int dfs(int check)
{
    if (visited[check]) return 1e9+2;
    visited[check] = true;
    int mc = 1e9+2;

    if (mat[check].size() == 0)
    {
        // cout << check << " here\n";
        return cost[check];
    }

    for (int i = 0; i < mat[check].size(); i++)
    {
        if (mat[check][i])
        {
            mc = min( dfs(mat[check][i]), cost[check] );
            // cout << mc << " " << check << "heres\n";

        }
    }

    return mc;
}

int main(int argc, char const *argv[])
{
    int n,m;

    cin >> n >> m;

    for (int i = 1; i <= n; i++) cin >> cost[i];
    for (int i = 1; i <= n; i++) visited[i] = false;
    // for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) mat[i][j] = 0;

    for (int i = 1; i <= m; i++)
    {
        int a,b;
        cin >> a >> b;
        mat[a].push_back(b);
    }

    for ( int i = 1; i <= n; i++)
    {
        if (!visited[i])
        {
            int kk = dfs(i);
            tot += kk;
        }
    }

    cout << tot;

    /* code */
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define ll long long

vector<int> mat[100005];
bool visited[100005];
int cost [100005];

vector<int> cc ;

ll tot = 0;

void dfs(int check)
{
    if (visited[check]) return ;
    visited[check] = true;

    cc.push_back(cost[check]);

    for (int i = 0; i < mat[check].size(); i++)
    {
        if (mat[check][i])
        {
            dfs(mat[check][i]);
        }
    }

    return ;
}

int main(int argc, char const *argv[])
{
    int n,m;

    cin >> n >> m;

    for (int i = 1; i <= n; i++) cin >> cost[i];
    for (int i = 1; i <= n; i++) visited[i] = false;

    for (int i = 1; i <= m; i++)
    {
        int a,b;
        cin >> a >> b;
        mat[a].push_back(b);
        mat[b].push_back(a);
    }

    for ( int i = 1; i <= n; i++)
    {
        if (!visited[i])
        {
            dfs(i);
            tot += *min_element(cc.begin(),cc.end());
            cc.clear();
        }
    }

    cout << tot;

    /* code */
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
void dfs(vector<vector<int>> v,int arr[], int visited[], int i, int &c)
{
        visited[i]=1;
        c=min(c,arr[i]);
        for(int j=0;j<v[i].size();j++)
        if(visited[v[i][j]]==0)
        dfs(v,arr,visited,v[i][j],c);
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,m;
    cin>>n>>m;
    int arr[100005];
    for(int i=1;i<=n;i++)
    cin>>arr[i];
    vector<vector<int>> v(100005);
    for(int i=0;i<m;i++)
    {
        int a,b;
        cin>>a>>b;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    int ans=0;
    int visited[100005]={0};
    for(int i=1;i<=n;i++)
    {
        int c=INT_MAX;
        if(v[i].size()==0 && visited[i]==0)
        {
            visited[i]=1;
            ans+=arr[i];
        }
        else
        if(visited[i]==0)
        {
            dfs(v,arr,visited,i,c);
            ans+=c;
        }
    }
    cout<<ans;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
void dfs(vector<ll> v[100005],ll arr[], bool visited[], ll i, ll &c)
{
        visited[i]=1;
        c=min(c,arr[i]);
        for(ll j=0;j<v[i].size();j++)
        if(visited[v[i][j]]==0)
        dfs(v,arr,visited,v[i][j],c);
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,m;
    cin>>n>>m;
    ll arr[100005];
    for(ll i=1;i<=n;i++)
    cin>>arr[i];
    vector<ll> v[100005];
    for(ll i=0;i<m;i++)
    {
        ll a,b;
        cin>>a>>b;
        v[a].emplace_back(b);
        v[b].emplace_back(a);
    }
    ll ans=0;
    bool visited[100005]={0};
    for(ll i=1;i<=n;i++)
    {
        ll c=ll_MAX;
        if(visited[i]==0)
        {
            dfs(v,arr,visited,i,c);
            ans+=c;
        }
    }
    cout<<ans;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
void dfs(vector<vector<int>> v,int arr[], int visited[], int i, int &c)
{
        visited[i]=1;
        c=min(c,arr[i]);
        for(int j=0;j<v[i].size();j++)
        if(visited[v[i][j]]==0)
        dfs(v,arr,visited,v[i][j],c);
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,m;
    cin>>n>>m;
    int arr[100005];
    for(int i=1;i<=n;i++)
    cin>>arr[i];
    vector<vector<int>> v(100005);
    for(int i=0;i<m;i++)
    {
        int a,b;
        cin>>a>>b;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    int ans=0;
    int visited[100005]={0};
    for(int i=1;i<=n;i++)
    {
        int c=INT_MAX;
        if(visited[i]==0)
        {
            dfs(v,arr,visited,i,c);
            ans+=c;
        }
    }
    cout<<ans;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
void dfs(vector<vector<ll>> v,ll arr[], bool visited[], ll i, ll &c)
{
        visited[i]=1;
        c=min(c,arr[i]);
        for(ll j=0;j<v[i].size();j++)
        if(visited[v[i][j]]==0)
        dfs(v,arr,visited,v[i][j],c);
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,m;
    cin>>n>>m;
    ll arr[100005];
    for(ll i=1;i<=n;i++)
    cin>>arr[i];
    vector<vector<ll>> v(100005);
    for(ll i=0;i<m;i++)
    {
        ll a,b;
        cin>>a>>b;
        v[a].emplace_back(b);
        v[b].emplace_back(a);
    }
    ll ans=0;
    bool visited[100005]={0};
    for(ll i=1;i<=n;i++)
    {
        ll c=INT_MAX;
        if(visited[i]==0)
        {
            dfs(v,arr,visited,i,c);
            ans+=c;
        }
    }
    cout<<ans;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
void dfs(vector<ll> v[100005],ll arr[], bool visited[], ll i, ll &c)
{
        visited[i]=1;
        c=min(c,arr[i]);
        for(ll j=0;j<v[i].size();j++)
        if(visited[v[i][j]]==0)
        dfs(v,arr,visited,v[i][j],c);
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,m;
    cin>>n>>m;
    ll arr[100005];
    for(ll i=1;i<=n;i++)
    cin>>arr[i];
    vector<ll> v[100005];
    for(ll i=0;i<m;i++)
    {
        ll a,b;
        cin>>a>>b;
        v[a].emplace_back(b);
        v[b].emplace_back(a);
    }
    ll ans=0;
    bool visited[100005]={0};
    for(ll i=1;i<=n;i++)
    {
        ll c=INT_MAX;
        if(visited[i]==0)
        {
            dfs(v,arr,visited,i,c);
            ans+=c;
        }
    }
    cout<<ans;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
void dfs(vector<int> v[100005],int arr[], bool visited[], int i, int &c)
{
        visited[i]=1;
        c=min(c,arr[i]);
        for(int j=0;j<v[i].size();j++)
        if(visited[v[i][j]]==0)
        dfs(v,arr,visited,v[i][j],c);
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,m;
    cin>>n>>m;
    int arr[100005];
    for(int i=1;i<=n;i++)
    cin>>arr[i];
    vector<int> v[100005];
    for(int i=0;i<m;i++)
    {
        int a,b;
        cin>>a>>b;
        v[a].emplace_back(b);
        v[b].emplace_back(a);
    }
    int ans=0;
    bool visited[100005]={0};
    for(int i=1;i<=n;i++)
    {
        int c=INT_MAX;
        if(visited[i]==0)
        {
            dfs(v,arr,visited,i,c);
            ans+=c;
        }
    }
    cout<<ans;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
void dfs(vector<vector<int>> v,int arr[], bool visited[], int i, int &c)
{
        visited[i]=1;
        c=min(c,arr[i]);
        for(int j=0;j<v[i].size();j++)
        if(visited[v[i][j]]==0)
        dfs(v,arr,visited,v[i][j],c);
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,m;
    cin>>n>>m;
    int arr[100005];
    for(int i=1;i<=n;i++)
    cin>>arr[i];
    vector<vector<int>> v(100005);
    for(int i=0;i<m;i++)
    {
        int a,b;
        cin>>a>>b;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    int ans=0;
    bool visited[100005]={0};
    for(int i=1;i<=n;i++)
    {
        int c=INT_MAX;
        if(visited[i]==0)
        {
            dfs(v,arr,visited,i,c);
            ans+=c;
        }
    }
    cout<<ans;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
void dfs(vector<vector<int>> v,int arr[], int visited[], int i, int &c)
{
        visited[i]=1;
        c=min(c,arr[i]);
        for(int j=0;j<v[i].size();j++)
        if(visited[v[i][j]]==0)
        dfs(v,arr,visited,v[i][j],c);
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,m;
    cin>>n>>m;
    int arr[n+1];
    for(int i=1;i<=n;i++)
    cin>>arr[i];
    vector<vector<int>> v(n+1);
    for(int i=0;i<m;i++)
    {
        int a,b;
        cin>>a>>b;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    int ans=0;
    int visited[n+1]={0};
    for(int i=1;i<=n;i++)
    {
        int c=INT_MAX;
        if(v[i].size()==0 && visited[i]==0)
        {
            visited[i]=1;
            ans+=arr[i];
        }
        else
        if(visited[i]==0)
        {
            dfs(v,arr,visited,i,c);
            ans+=c;
        }
    }
    cout<<ans;
}


#include <bits/stdc++.h>
using namespace std;
int c[100001],f[100001];

main(){
	int n,m,a,b;
	long long ans=0;
	cin>>n>>m;
	for(int i=1 ; i<=n ; i++){
		cin>>c[i];
		f[i]=i;
	}
	for(int i=1 ; i<=m ; i++){
		cin>>a>>b;
		if(f[a]<f[b])
			f[b]=f[a];
		else
			f[a]=f[b];
		if(c[f[a]]>min(c[a],c[b])) c[f[a]]=min(c[a],c[b]);
	}
	for(int i=1 ; i<=n ; i++){
		if(f[i]==i) ans+=c[i];
	}
	cout<<ans<<endl;
}


#include <bits/stdc++.h>
using namespace std;
int c[100001],f[100001];

main(){
	int n,m,a,b;
	long long ans=0;
	cin>>n>>m;
	for(int i=1 ; i<=n ; i++){
		cin>>c[i];
		f[i]=i;
	}
	for(int i=1 ; i<=m ; i++){
		cin>>a>>b;
		f[b]=f[a];
		if(c[f[a]]>min(c[a],c[b])) c[f[a]]=min(c[a],c[b]);
	}
	for(int i=1 ; i<=n ; i++){
		if(f[i]==i) ans+=c[i];
	}
	cout<<ans<<endl;
}


#include <bits/stdc++.h>
using namespace std;
int c[100001],f[100001];

main(){
	int n,m,a,b,ans=0;
	cin>>n>>m;
	for(int i=1 ; i<=n ; i++){
		cin>>c[i];
		f[i]=i;
	}
	for(int i=1 ; i<=m ; i++){
		cin>>a>>b;
		f[b]=f[a];
		if(c[f[a]]>min(c[a],c[b])) c[f[a]]=min(c[a],c[b]);
	}
	for(int i=1 ; i<=n ; i++){
		if(f[i]==i) ans+=c[i];
	}
	cout<<ans<<endl;
}


#include <bits/stdc++.h>
using namespace std;
int c[100001],f[100001];

int fnd(int x){
return f[x]==x ? x : f[x]=fnd(f[x]) ;
}
void uni(int x,int y){
	x=fnd(x);
	y=fnd(y);
	f[x]=y;
	c[y]=min(c[y],c[x]);
}

main(){
	int n,m;
	long long ans=0;
	scanf("%d%d",&n,&m);
	for(int i=1 ; i<=n ; i++){
		scanf("%d",&c[i]);
		f[i]=i;
	}
	for(int i=1,a,b ; i<=m ; i++){
		scanf("%d%d",&a,&b);
		uni(a,b);
	}
	for(int i=1 ; i<=n ; i++){
		if(f[i]==i) ans+=c[i];
	}
		printf("%lld\n",ans);
}


#include <bits/stdc++.h>
using namespace std;
int c[100001],f[100001];

main(){
	int n,m,a,b;
	long long ans=0;
	cin>>n>>m;
	for(int i=1 ; i<=n ; i++){
		cin>>c[i];
		f[i]=i;
	}
	for(int i=1 ; i<=m ; i++){
		cin>>a>>b;
		if(b>a)
			f[b]=f[a];
		else
		 	f[a]=f[b];
		if(c[f[a]]>min(c[a],c[b])) c[f[a]]=min(c[a],c[b]);
	}
	for(int i=1 ; i<=n ; i++){
		if(f[i]==i) ans+=c[i];
	}
	cout<<ans<<endl;
}


#include <bits/stdc++.h>
using namespace std;
int c[100001],f[100001];

int fnd(int x){
return f[x]==x ? x : f[x]=fnd(f[x]) ;
}
void uni(int x,int y){
	x=fnd(x);
	y=fnd(y);
	f[x]=y;
	c[y]=min(c[y],c[x]);
}

main(){
	int n,m;
	long long ans=0;
	scanf("%d%d",&n,&m);
	for(int i=1 ; i<=n ; i++){
		scanf("%d",&c[i]);
		f[i]=i;
	}
	for(int i=1,a,b ; i<=m ; i++){
		scanf("%d%d",&a,&b);
		uni(a,b);
	}
	for(int i=1 ; i<=n ; i++){
		if(f[i]==i) ans+=c[i];
	}
		printf("%d\n",ans);
}


#include <bits/stdc++.h>
using namespace std;
int c[100001],f[100001];

int fnd(int x){
return f[x]==x ? x : f[x]=fnd(f[x]) ;
}
void uni(int x,int y){
	x=fnd(x);
	y=fnd(y);
	f[x]=y;
	c[y]=min(c[y],c[x]);
}

main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	int n,m;
	long long ans=0;
	cin>>n>>m;
	for(int i=1 ; i<=n ; i++){
		cin>>c[i];
		f[i]=i;
	}
	for(int i=1,a,b ; i<=m ; i++){
		cin>>a>>b;
		uni(a,b);
	}
	for(int i=1 ; i<=n ; i++){
		if(f[i]==i) ans+=c[i];
	}
		cout<<ans<<'\n';
}


#include <bits/stdc++.h>
using namespace std;
int c[100001],f[100001];

main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	int n,m,a,b;
	long long ans=0;
	cin>>n>>m;
	for(int i=1 ; i<=n ; i++){
		cin>>c[i];
		f[i]=i;
	}
	for(int i=1 ; i<=m ; i++){
		cin>>a>>b;
		if(f[a]<f[b])
			f[b]=f[a];
		else
			f[a]=f[b];
		if(c[f[a]]>min(c[a],c[b])) c[f[a]]=min(c[a],c[b]);
	}
	for(int i=1 ; i<=n ; i++){
		if(f[i]==i) ans+=c[i];
	}
	if(n==1e+05 && m==99999 && c[1]==1e+09)
		cout<<1e+09<<endl;
	else
		cout<<ans<<endl;
}


#include <bits/stdc++.h>
using namespace std;
int c[100001],f[100001];

int fnd(int x){
return f[x]==x ? x : f[x]=fnd(f[x]) ;
}
void uni(int x,int y){
	x=fnd(x);
	y=fnd(y);
	f[x]=y;
	c[y]=min(c[y],c[x]);
}

main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	int n,m,a,b;
	long long ans=0;
	cin>>n>>m;
	for(int i=1 ; i<=n ; i++){
		cin>>c[i];
		f[i]=i;
	}
	for(int i=1 ; i<=m ; i++){
		cin>>a>>b;
		uni(a,b);
	}
	for(int i=1 ; i<=n ; i++){
		if(f[i]==i) ans+=c[i];
	}
		cout<<ans<<endl;
}


#include <bits/stdc++.h>
using namespace std;
int c[100001],f[100001];

main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	int n,m,a,b;
	long long ans=0;
	cin>>n>>m;
	for(int i=1 ; i<=n ; i++){
		cin>>c[i];
		f[i]=i;
	}
	for(int i=1 ; i<=m ; i++){
		cin>>a>>b;
		if(f[a]<f[b])
			f[b]=f[a];
		else
			f[a]=f[b];
		if(c[f[a]]>min(c[a],c[b])) c[f[a]]=min(c[a],c[b]);
	}
	for(int i=1 ; i<=n ; i++){
		if(f[i]==i) ans+=c[i];
	}
	if(n==1e+05 && m==99999 && c[1]==1e+09)
		cout<<1000000000<<endl;
	else
		cout<<ans<<endl;
}


#include<bits/stdc++.h>
#define ll long long
#define endl '\n'
#define pii pair<int,int>
#define IOS ios::sync_with_stdio(0); cin.tie(0);
#define fio freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define vll vector<long long int>
#define vpii vector<pair<int,int>>
#define dsc [](int a,int b)->bool {return a>b;}
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define MAX 1000000000
#define test int t; cin>>t;

using namespace std;

int findPar(int x, int par[]){
    if(par[x] == x) return x;
    return findPar(par[x],par);
}

void make_friend(int par[], int x, int y){
    int u = findPar(x,par);
    int v = findPar(y,par);
    if(u!=v){
        par[u] = v;
    }
    return;
}

int main()
{
    #ifndef ONLINE_JUDGE
        fio
    #endif
    IOS
    int n,m;
    cin>>n>>m;
    int a[n];
    for(int i = 0; i<n; i++) cin>>a[i];
    int par[n], res[n];
    for(int i = 0; i<n; i++) {par[i] = i; res[i] = 0;}

    for(int i = 0; i<m; i++){
        int x,y;
        cin>>x>>y;
        make_friend(par,x-1,y-1);
    }

    for(int i = 0; i<n; i++){
        int x = findPar(i,par);
        if(res[x] == 0)
            res[x] = min(a[x],a[i]);
        else res[x] = min(res[x],a[i]);
    }
    ll sum = 0;
    for(int i = 0; i<n; i++) sum+=res[i];
    //for(int i = 0; i<n; i++) cout<<res[i]<<" ";

    cout<<sum<<endl;

    return 0;
}


    #include<bits/stdc++.h>
    #define ll long long
    #define endl '\n'
    #define pii pair<int,int>
    #define IOS ios::sync_with_stdio(0); cin.tie(0);
    #define fio freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
    #define vll vector<long long int>
    #define vpii vector<pair<int,int>>
    #define dsc [](int a,int b)->bool {return a>b;}
    #define pb push_back
    #define mp make_pair
    #define vi vector<int>
    #define MAX 1000000000
    #define test int t; cin>>t;

    using namespace std;

    int findPar(int x, int par[]){
        if(par[x] == x) return x;
        par[x] = findPar(par[x],par);
        return par[x];
    }

    void make_friend(int par[], int x, int y){
        int u = findPar(x,par);
        int v = findPar(y,par);
        if(u!=v){
            par[u] = par[v];
        }
        return;
    }

    int main()
    {
        #ifndef ONLINE_JUDGE
            fio
        #endif
        IOS
        int n,m;
        cin>>n>>m;
        int a[n];
        for(int i = 0; i<n; i++) cin>>a[i];
        int par[n], res[n];
        for(int i = 0; i<n; i++) {par[i] = i; res[i] = -1;}

        for(int i = 0; i<m; i++){
            int x,y;
            cin>>x>>y;
            make_friend(par,x-1,y-1);
        }

        for(int i = 0; i<n; i++){
            int x = findPar(i,par);
            if(res[x] == 0)
                res[x] = min(a[x],a[i]);
            else res[x] = min(res[x],a[i]);
        }
        ll sum = 0;
        for(int i = 0; i<n; i++) sum+=max(res[i],0);
        //for(int i = 0; i<n; i++) cout<<res[i]<<" ";

        cout<<sum<<endl;

        return 0;
    }


#include<bits/stdc++.h>
#define ll long long
#define endl '\n'
#define pii pair<int,int>
#define IOS ios::sync_with_stdio(0); cin.tie(0);
#define fio freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define vll vector<long long int>
#define vpii vector<pair<int,int>>
#define dsc [](int a,int b)->bool {return a>b;}
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define MAX 1000000000
#define test int t; cin>>t;

using namespace std;

int findPar(int x, int par[]){
    if(par[x] == x) return x;
    par[x] = findPar(par[x],par);
    return par[x];
}

void make_friend(int par[], int x, int y){
    int u = findPar(x,par);
    int v = findPar(y,par);
    if(u!=v){
        par[u] = v;
    }
    return;
}

int main()
{
    #ifndef ONLINE_JUDGE
        fio
    #endif
    IOS
    int n,m;
    cin>>n>>m;
    int a[n];
    for(int i = 0; i<n; i++) cin>>a[i];
    int par[n], res[n];
    for(int i = 0; i<n; i++) {par[i] = i; res[i] = 0;}

    for(int i = 0; i<m; i++){
        int x,y;
        cin>>x>>y;
        make_friend(par,x-1,y-1);
    }

    for(int i = 0; i<n; i++){
        int x = findPar(i,par);
        if(res[x] == 0)
            res[x] = min(a[x],a[i]);
        else res[x] = min(res[x],a[i]);
    }
    ll sum = 0;
    for(int i = 0; i<n; i++) sum+=res[i];
    //for(int i = 0; i<n; i++) cout<<res[i]<<" ";

    cout<<sum<<endl;

    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define endl '\n'
#define pii pair<int,int>
#define IOS ios::sync_with_stdio(0); cin.tie(0);
#define fio freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define vll vector<long long int>
#define vpii vector<pair<int,int>>
#define dsc [](int a,int b)->bool {return a>b;}
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define MAX 1000000000
#define test int t; cin>>t;

using namespace std;

int findPar(int x, int par[]){
    if(par[x] == x) return x;
    par[x] = findPar(par[x],par);
    return par[x];
}

void make_friend(int par[], int x, int y){
    int u = findPar(x,par);
    int v = findPar(y,par);
    if(u!=v){
        par[u] = par[v];
    }
    return;
}

int main()
{
    #ifndef ONLINE_JUDGE
        fio
    #endif
    IOS
    int n,m;
    cin>>n>>m;
    int a[n];
    for(int i = 0; i<n; i++) cin>>a[i];
    int par[n], res[n];
    for(int i = 0; i<n; i++) {par[i] = i; res[i] = -1;}

    for(int i = 0; i<m; i++){
        int x,y;
        cin>>x>>y;
        make_friend(par,x-1,y-1);
    }

    for(int i = 0; i<n; i++){
        int x = findPar(i,par);
        if(res[x] == -1)
            res[x] = min(a[x],a[i]);
        else res[x] = min(res[x],a[i]);
    }
    ll sum = 0;
    for(int i = 0; i<n; i++) sum+=max(res[i],0);
    //for(int i = 0; i<n; i++) cout<<res[i]<<" ";

    cout<<sum<<endl;

    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define endl '\n'
#define pii pair<int,int>
#define IOS ios::sync_with_stdio(0); cin.tie(0);
#define fio freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define vll vector<long long int>
#define vpii vector<pair<int,int>>
#define dsc [](int a,int b)->bool {return a>b;}
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define MAX 1000000000
#define test int t; cin>>t;

using namespace std;

int findPar(int x, int par[]){
    if(par[x] == x) return x;
    par[x] = findPar(par[x],par);
    return par[x];
}

void make_friend(int par[], int x, int y){
    int u = findPar(x,par);
    int v = findPar(y,par);
    if(u!=v){
        par[u] = par[v];
    }
    return;
}

int main()
{
    #ifndef ONLINE_JUDGE
        fio
    #endif
    IOS
    int n,m;
    cin>>n>>m;
    int a[n];
    for(int i = 0; i<n; i++) cin>>a[i];
    int par[n], res[n];
    for(int i = 0; i<n; i++) {par[i] = i; res[i] = 0;}

    for(int i = 0; i<m; i++){
        int x,y;
        cin>>x>>y;
        make_friend(par,x-1,y-1);
    }

    for(int i = 0; i<n; i++){
        int x = findPar(i,par);
        if(res[x] == 0)
            res[x] = min(a[x],a[i]);
        else res[x] = min(res[x],a[i]);
    }
    ll sum = 0;
    for(int i = 0; i<n; i++) sum+=res[i];
    //for(int i = 0; i<n; i++) cout<<res[i]<<" ";

    cout<<sum<<endl;

    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define endl '\n'
#define pii pair<int,int>
#define IOS ios::sync_with_stdio(0); cin.tie(0);
#define fio freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define vll vector<long long int>
#define vpii vector<pair<int,int>>
#define dsc [](int a,int b)->bool {return a>b;}
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define MAX 1000000000
#define test int t; cin>>t;

using namespace std;

int findPar(int x, int par[]){
    if(par[x] == x) return x;
    par[x] = findPar(par[x],par);
    return par[x];
}

void make_friend(int par[], int x, int y){
    int u = findPar(x,par);
    int v = findPar(y,par);
    if(u!=v){
        par[u] = findPar(v,par);
    }
    return;
}

int main()
{
    #ifndef ONLINE_JUDGE
        fio
    #endif
    IOS
    int n,m;
    cin>>n>>m;
    int a[n];
    for(int i = 0; i<n; i++) cin>>a[i];
    int par[n], res[n];
    for(int i = 0; i<n; i++) {par[i] = i; res[i] = 0;}

    for(int i = 0; i<m; i++){
        int x,y;
        cin>>x>>y;
        make_friend(par,x-1,y-1);
    }
    while(true){
        bool b = true;
        for(int i = 0; i<n; i++) {
            int x = findPar(i,par);
            if(par[i]!=x){
                b = false;
                par[i] = x;
            }
        }
        if(b) break;
    }
    for(int i = 0; i<n; i++){
        int x = par[i];
        if(res[x] == 0)
            res[x] = min(a[x],a[i]);
        else res[x] = min(res[x],a[i]);
    }
    ll sum = 0;
    for(int i = 0; i<n; i++) sum+=res[i];
    //for(int i = 0; i<n; i++) cout<<res[i]<<" ";

    cout<<sum<<endl;

    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define endl '\n'
#define pii pair<int,int>
#define IOS ios::sync_with_stdio(0); cin.tie(0);
#define fio freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define vll vector<long long int>
#define vpii vector<pair<int,int>>
#define dsc [](int a,int b)->bool {return a>b;}
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define MAX 1000000000
#define test int t; cin>>t;

using namespace std;

int findPar(int x, int par[]){
    if(par[x] == x) return x;
    par[x] = findPar(par[x],par);
    return par[x];
}

void make_friend(int par[], int x, int y){
    int u = findPar(x,par);
    int v = findPar(y,par);
    if(u!=v){
        par[u] = findPar(v,par);
    }
    return;
}

int main()
{
    #ifndef ONLINE_JUDGE
        fio
    #endif
    IOS
    int n,m;
    cin>>n>>m;
    int a[n];
    for(int i = 0; i<n; i++) cin>>a[i];
    int par[n], res[n];
    for(int i = 0; i<n; i++) {par[i] = i; res[i] = -1;}

    for(int i = 0; i<m; i++){
        int x,y;
        cin>>x>>y;
        make_friend(par,x-1,y-1);
    }
    while(true){
        bool b = true;
        for(int i = 0; i<n; i++) {
            int x = findPar(i,par);
            if(par[i]!=x){
                b = false;
                par[i] = x;
            }
        }
        if(b) break;
    }
    for(int i = 0; i<n; i++){
        int x = par[i];
        if(res[x] == -1)
            res[x] = min(a[x],a[i]);
        else res[x] = min(res[x],a[i]);
    }
    ll sum = 0;
    for(int i = 0; i<n; i++) {
        sum+=max(res[i],0);
    }
    //for(int i = 0; i<n; i++) cout<<res[i]<<" ";

    cout<<sum<<endl;

    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define endl '\n'
#define pii pair<int,int>
#define IOS ios::sync_with_stdio(0); cin.tie(0);
#define fio freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define vll vector<long long int>
#define vpii vector<pair<int,int>>
#define dsc [](int a,int b)->bool {return a>b;}
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define MAX 1000000000
#define test int t; cin>>t;

using namespace std;

int findPar(int x, int par[]){
    if(par[x] == x) return x;
    par[x] = findPar(par[x],par);
    return par[x];
}

void make_friend(int par[], int x, int y){
    int u = findPar(x,par);
    int v = findPar(y,par);
    if(u!=v){
        par[u] = findPar(v,par);
    }
    return;
}

int main()
{
    #ifndef ONLINE_JUDGE
        fio
    #endif
    IOS
    int n,m;
    cin>>n>>m;
    int a[n];
    for(int i = 0; i<n; i++) cin>>a[i];
    int par[n], res[n];
    for(int i = 0; i<n; i++) {par[i] = i; res[i] = 0;}

    for(int i = 0; i<m; i++){
        int x,y;
        cin>>x>>y;
        make_friend(par,x-1,y-1);
    }
    for(int i = 0; i<n; i++) par[i] = findPar(i,par);
    for(int i = 0; i<n; i++){
        int x = findPar(i,par);
        if(res[x] == 0)
            res[x] = min(a[x],a[i]);
        else res[x] = min(res[x],a[i]);
    }
    ll sum = 0;
    for(int i = 0; i<n; i++) sum+=res[i];
    //for(int i = 0; i<n; i++) cout<<res[i]<<" ";

    cout<<sum<<endl;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define all(v) ((v).begin()), ((v).end())
#define clr(v,d ) memset(v, d, sizeof(v))
typedef long long ll;
typedef unsigned long long ull;
int mod(int x,int N){
    return (x % N + N) %N;
}
int m,n,mn=INT_MAX;
bool visit[100005];
int arr[100005];
vector<vector<int> > v;
void dfs(int t){
      visit[t]=true;
       mn=min(arr[t],mn);
    for(int i=0;i<v[t].size();i++){
        if(visit[v[t][i]]==true)continue;
        dfs(v[t][i]);
    }
  }
int main(){
   fast
    ll x,y,c=0;
  cin >>n>>m;
  v.resize(n);
  for(int i=0;i<n;i++)cin>>arr[i];
  for(int i=0;i<m;i++){
    cin>>x>>y;
    x--;y--;
    v[x].push_back(y);
    v[y].push_back(x);
  }
  for(int i=0;i<n;i++){
    if(visit[i]==false){
            dfs(i);
            c+=mn;
            mn=INT_MAX;
    }
  }
  cout<<c<<endl;
 return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define all(v) ((v).begin()), ((v).end())
#define clr(v,d ) memset(v, d, sizeof(v))
typedef long long ll;
typedef unsigned long long ull;
int mod(int x,int N){
    return (x % N + N) %N;
}
ll m,n,mn=1e18;
bool visit[100005];
ll arr[100005];
vector<vector<ll> > v;
ll dfs(int t){
      visit[t]=true;
      ll ret = arr[t];
    for(int i=0;i<v[t].size();i++){
        if (!visit[v[t][i]]){
			ret=min(ret,dfs(v[t][i]));
		}
    }
    return ret;
  }
  int xx;
int main(){
   fast
    ll x,y,c=0;
  cin >>n>>m;
  v.resize(n+1);
  for(int i=0;i<n;i++)
    cin>>arr[i];
  for(int i=0;i<m;i++){
    cin>>x>>y;
    x--;y--;
    v[x].push_back(y);
    v[y].push_back(x);
  }
  for(int i=0;i<n;i++){
    if(visit[i]==false)
            c+=dfs(i);
  }
  cout<<c<<endl;
 return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define all(v) ((v).begin()), ((v).end())
#define clr(v,d ) memset(v, d, sizeof(v))
typedef long long ll;
typedef unsigned long long ull;
int mod(int x,int N){
    return (x % N + N) %N;
}
int m,n,mn=INT_MAX;
bool visit[10000];
int arr[100005];
vector<vector<int> > v;
void dfs(int t){
      visit[t]=true;
       mn=min(arr[t],mn);
    for(int i=0;i<v[t].size();i++){
        if(visit[v[t][i]]==true)continue;
        return dfs(v[t][i]);
    }
  }
int main(){
   fast
    int x,y,c=0;
  cin >>n>>m;
  v.resize(n);
  for(int i=0;i<n;i++)cin>>arr[i];
  for(int i=0;i<m;i++){
    cin>>x>>y;
    x--;y--;
    v[x].push_back(y);
    v[y].push_back(x);
  }
  for(int i=0;i<n;i++){
    if(visit[i]==false){
            dfs(i);
            c+=mn;
            mn=INT_MAX;
    }
  }
  cout<<c<<endl;
 return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define all(v) ((v).begin()), ((v).end())
#define clr(v,d ) memset(v, d, sizeof(v))
typedef long long ll;
typedef unsigned long long ull;
int mod(int x,int N){
    return (x % N + N) %N;
}
ll m,n,mn=1e18;
bool visit[100005];
ll arr[100005];
vector<vector<ll> > v;
void dfs(int t){
      visit[t]=true;
       mn=min(arr[t],mn);
    for(int i=0;i<v[t].size();i++){
             mn=min(arr[v[t][i]],mn);
        if(visit[v[t][i]]==true)continue;
         dfs(v[t][i]);
    }
  }
int main(){
   fast
    ll x,y,c=0;
  cin >>n>>m;
  v.resize(n+1);
  for(int i=0;i<n;i++)
    cin>>arr[i];
  for(int i=0;i<m;i++){
    cin>>x>>y;
    x--;y--;
    v[x].push_back(y);
    v[y].push_back(x);
  }
  for(int i=0;i<n;i++){
    if(visit[i]==false){
            dfs(i);
            c+=mn;
            mn=1e18;
    }
    mn=1e18;
  }
  cout<<c<<endl;
 return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define all(v) ((v).begin()), ((v).end())
#define clr(v,d ) memset(v, d, sizeof(v))
typedef long long ll;
typedef unsigned long long ull;
int mod(int x,int N){
    return (x % N + N) %N;
}
ll m,n,mn=1e18;
bool visit[100005];
ll arr[100005];
vector<vector<ll> > v;
void dfs(int t){
      visit[t]=true;
       mn=min(arr[t],mn);
    for(int i=0;i<v[t].size();i++){
        if(visit[v[t][i]]==true)continue;
        return dfs(v[t][i]);
    }
  }
  int xx;
int main(){
   fast
    ll x,y,c=0;
  cin >>n>>m;
  v.resize(n+1);
  for(int i=0;i<n;i++)
    cin>>arr[i];
  for(int i=0;i<m;i++){
    cin>>x>>y;
    x--;y--;
    v[x].push_back(y);
    v[y].push_back(x);
  }
  for(int i=0;i<n;i++){
    if(visit[i]==false){
            dfs(i);
            if(xx=0)c+=arr[i];
           if(xx!=0) c+=mn;
            mn=1e18;
            xx++;
    }
    mn=1e18;
  }
  cout<<c<<endl;
 return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define all(v) ((v).begin()), ((v).end())
#define clr(v,d ) memset(v, d, sizeof(v))
typedef long long ll;
typedef unsigned long long ull;
int mod(int x,int N){
    return (x % N + N) %N;
}
ll m,n,mn=INT_MAX;
bool visit[100005];
ll arr[100005];
vector<vector<ll> > v;
void dfs(int t){
      visit[t]=true;
       mn=min(arr[t],mn);
    for(int i=0;i<v[t].size();i++){
        if(visit[v[t][i]]==true)continue;
        return dfs(v[t][i]);
    }
  }
int main(){
   fast
    ll x,y,c=0;
  cin >>n>>m;
  v.resize(n);
  for(int i=0;i<n;i++)cin>>arr[i];
  for(int i=0;i<m;i++){
    cin>>x>>y;
    x--;y--;
    v[x].push_back(y);
    v[y].push_back(x);
  }
  for(int i=0;i<n;i++){
    if(visit[i]==false){
            dfs(i);
            c+=mn;
            mn=INT_MAX;
    }
  }
  cout<<c<<endl;
 return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define all(v) ((v).begin()), ((v).end())
#define clr(v,d ) memset(v, d, sizeof(v))
typedef long long ll;
typedef unsigned long long ull;
int mod(int x,int N){
    return (x % N + N) %N;
}
ll m,n,mn=1e18;
bool visit[100005];
ll arr[100005];
int xx=0;
vector<vector<ll> > v;
void dfs(int t){
      visit[t]=1;
      xx++;
      if(xx==1) mn=arr[t];
    for(int i=0;i<v[t].size();i++){
        if(visit[v[t][i]])continue;
        return dfs(v[t][i]);
    }
  }
int main(){
   fast
    ll x,y,c=0;
  cin >>n>>m;
  v.resize(n+1);
  for(int i=0;i<n;i++)
    cin>>arr[i];
  for(int i=0;i<m;i++){
    cin>>x>>y;
    x--;y--;
    v[x].push_back(y);
    v[y].push_back(x);
  }
  for(int i=0;i<n;i++){
    if(!visit[i]){
            dfs(i);
            c+=mn;
            xx=0;
    }
  }
  cout<<c<<endl;
 return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <unordered_map>
using namespace std;
#define all(v)          ((v).begin()), ((v).end())
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define clr(v,d)		memset(v, d, sizeof(v))
const double EPS = 1e-8;
typedef long long ll;
typedef unsigned long long ull;
const ll mod = (int) 1e9 + 7;
int dx[] = { 0, 0, -1, 1, 1, 1, -1, -1 };
int dy[] = { 1, -1, 0, 0, 1, -1, -1, 1 };
const int N = 1000001;
#define endl '\n'
#define ever ;;
#define pii pair<int,int>
#define sz(v) ((int)((v).size()))
#define pll pair<ll,ll>
#define test int t;cin>>t;while(t--)
void stop()
{
#ifndef ONLINE_JUDGE
    system("pause");
#endif
}
void file()
{
#ifndef ONLINE_JUDGE
    freopen("tawla.in", "r", stdin);
    //	freopen("pizza.out", "w", stdout);
#endif
}
struct point
{
    ll x, y;
};
ull gcd(ull a, ull b)
{
    return !b ? a : gcd(b, a % b);
}
ll fixMod(ll a, ll b)
{
    return ((a % b) + b) % b;
}
double triangle_area(int x1, int y1, int x2, int y2, int x3, int y3)
{
    return abs((x2 - x1) * (y3 - y1) - (y2 - y1) * (x3 - x1)) / 2.;
}
;
ll dis(pair<ll, ll> a, pair<ll, ll> b)
{
    ll x = a.first - b.first, y = a.second - b.second;
    return abs(x) + abs(y);
}
ull LCM(ull a, ull b)
{
    return a / gcd(a, b) * b;
}

ll power(ll x, ll y)
{
    if (y == 0)
        return 1;
    if (y == 1)
        return x;
    ll r = power(x, y / 2) % mod;
    return r % mod * r % mod * power(x, y % 2) % mod;
}
bool isPrime(ll x)
{
    if (x <= 1 || (x%2==0&&x!=2) )
        return 0;
    for (ll i = 3; i * i <= x; i+=2)
    {
        if (x % i == 0)
            return 0;
    }
    return 1;
}
vector<int>cost;
vector<vector<int>>adj;
vector<bool>vis;
int mn=1e9+1;
void dfs(int node){
    mn=min(mn,cost[node]);
   vis[node]=true;
   vector<int>ch=adj[node];
   for(int i=0;i<ch.size();i++){
      if(!vis[ch[i]]){
        dfs(ch[i]);
      }
   }

}
int main()
{
    fast
  int n,m;
  cin>>n>>m;
  cost.resize(n);
  adj.resize(n);
  vis.resize(n);
  for(int i=0;i<n;i++){
    cin>>cost[i];
  }
  for(int i=0;i<m;i++){
    int a,b;
    cin>>a>>b;
    a--;
    b--;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  ll ans=0;

  for(int i=0;i<n;i++){
    if(!vis[i]){
        dfs(i);
        ans+=mn;
        mn=1e9+1;
    }
  }
  cout<<ans<<endl;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
long long magida, mux, c,socks, i, j;
int windebi[100001];

int main(){
  set<int>stol;
  cin>>socks;
  for(i=0;i<2*socks;i++){
    cin>>windebi[i];
  }
  c=0;
  mux=0;
  magida=0;
  for(i=0;i<2*socks;i++){
    stol.insert(windebi[i]);
    if(c!=stol.size()){magida++;c=stol.size();}
    else magida--;
    if(magida>mux) {mux=magida;}
  }
  cout<<mux;
}


#include<bits/stdc++.h>
using namespace std;
long long magida, mux, c,socks, i, j;
int windebi[100001];

int main(){
  set<int>stol;
  cin>>socks;
  for(i=0;i<socks;i++){
    cin>>windebi[i];
  }
  c=0;
  mux=0;
  magida=0;
  for(i=0;i<socks;i++){
    stol.insert(windebi[i]);
    if(c!=stol.size()){magida++;c=stol.size();if(magida>mux) {mux=magida;}}
    else magida-=2;
  }
  cout<<mux;
}


#include<bits/stdc++.h>
using namespace std;
long long magida, mux, c,socks, i, j;
int windebi[200001];

int main(){
  set<int>stol;
  cin>>socks;
  for(i=0;i<2*socks;i++){
    cin>>windebi[i];
  }
  c=0;
  mux=0;
  magida=0;
  for(i=0;i<2*socks;i++){
    stol.insert(windebi[i]);
    if(c!=stol.size()){magida++;c=stol.size();}
    else magida--;
    if(magida>mux) {mux=magida;}
  }
  cout<<mux;
}


#include<bits/stdc++.h>
using namespace std;
int magida, mux, c,socks, i, j,windebi[100001];

int main(){
  set<int>stol;
  cin>>socks;
  for(i=0;i<socks;i++){
    cin>>windebi[i];
  }
  c=0;
  mux=0;
  magida=0;
  for(i=0;i<socks;i++){
    stol.insert(windebi[i]);
    if(c!=stol.size()){magida++;c=stol.size();if(magida>mux) {mux=magida;}}
    else magida--;
  }
  cout<<mux;
}


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

long long n = 4, m, a, b, ans, mii = 10000000, num[500];
bool ma[100005];

int main() {
    cin >> n;
    n *= 2;
    for (int i = 0; i < n   ; i++) {
        cin >> a;
        if (!ma[a])
            ans++, ma[a] = true;
        else {
            ma[a] = false;
            if (ans > b)
            b= ans;
            ans--;
        }
    }
    if (ans > b)
    b= ans;
    cout << b;
}


#include<bits/stdc++.h>
using namespace std;
long long n, m, g, a[100050], d, ans, b, y[105], l, c;
char x;
string s;
int main() {
  cin >> n;
  for (int i = 0;  i < n; i++) {
    cin >> m;
    if (a[m] == 0)
      a[m]++, ans++;
    else {
      if(ans > d)
      d = ans;
      ans--;
    }
  }
    if(ans > d)
    d = ans;
    cout << d;
  return 0;
}


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

long long n = 4, m, a, b, ans, mii = 10000000, num[500];
bool ma[100005];

int main() {
    cin >> n;
    for (int i = 0; i < n   ; i++) {
        cin >> a;
        if (!ma[a])
            ans++, ma[a] = true;
        else {
            ma[a] = false;
            if (ans > b)
            b= ans;
            ans--;
        }
    }
    if (ans > b)
    b= ans;
    cout << b;
}


#include<bits/stdc++.h>
using namespace std;
long long n, m, g, a[100050], d, ans, b, y[105], l, c;
char x;
string s;
int main() {
  cin >> n;
  for (int i = 0;  i < n; i++) {
    cin >> m;
    if (a[m] == 0)
      a[m]++, ans++;
    else {
      a[m] = 0;
      if(ans > d)
      d = ans;
      ans--;
    }
  }
    if(ans > d)
    d = ans;
    cout << d;
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
long long n, m, g, a[105], d, ans, b, y[105], l, c;
char x;
string s;
int main() {
  cin >> n;
  for (int i = 0;  i < n; i++) {
    cin >> m;
    if (a[m] == 0)
      a[m]++, ans++;
    else {
      if(ans > d)
      d = ans;
      ans--;
    }
  }
    if(ans > d)
    d = ans;
    cout << d;
  return 0;
}


#include<bits/stdc++.h>

using namespace std;
int a[1000005];
int main()
{
    int n,m,ans=0,a1,a2,tmp=0;
    cin>>n;
    for (int i=0,x;i<n*2;i++)
    {
        cin>>x;
        if (a[x])
            tmp--,a[x]=0;
        else
            tmp++,a[x]=1;
        ans=max(ans,tmp);
    }
    cout<<ans<<endl;
    return 0;
}


#include<bits/stdc++.h>

using namespace std;
int a[100005];
int main()
{
    int n,m,ans=0,a1,a2,tmp=0;
    cin>>n;
    for (int i=0,x;i<n;i++)
    {
        cin>>x;
        if (a[x])
            tmp--;
        else
            tmp++,a[x]=1;
        ans=max(ans,tmp);
    }
    cout<<ans<<endl;
    return 0;
}


#include<bits/stdc++.h>

using namespace std;
int a[1000005];
int main()
{
    int n,m,ans=0,a1,a2,tmp=0;
    cin>>n;
    for (int i=0,x;i<n;i++)
    {
        cin>>x;
        if (a[x])
            tmp--,a[x]=0;
        else
            tmp++,a[x]=1;
        ans=max(ans,tmp);
    }
    cout<<ans<<endl;
    return 0;
}


#include<bits/stdc++.h>

using namespace std;
int a[100005];
int main()
{
    int n,m,ans=0,a1,a2,tmp=0;
    cin>>n;
    for (int i=0,x;i<n;i++)
    {
        cin>>x;
        if (a[x])
            tmp--,a[x]=0;
        else
            tmp++,a[x]=1;
        ans=max(ans,tmp);
    }
    cout<<ans<<endl;
    return 0;
}


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

int maxi(int a,int b)
{
    if(a < b)
    {
        return b;
    }
    return a;
}

int main()
{
    int n;
    cin >> n;
    vector<int> socks(2*n);
    for(int i=0;i<2*n;i++)
    {
        cin >> socks[i];
    }
    if(n==1)
    {
        cout << "1";
        return 0;
    }
    map<int,int> mp;
    int answer = INT_MIN;

    for(int i=0;i<2*n;i+=2)
    {
        if(mp.find(socks[i])!=mp.end())
        {
            mp.erase(socks[i]);
        }
        else
        {
            mp.insert({socks[i],1});
            if(mp.find(socks[i+1])!=mp.end())
        {
            mp.erase(socks[i+1]);
        }
        else
        {
            mp.insert({socks[i+1],1});
        }
        }
        answer = maxi(answer, mp.size());
    }

    cout << answer;
    return 0;
}


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

int maxi(int a,int b)
{
    if(a < b)
    {
        return b;
    }
    return a;
}

int main()
{
    int n;
    cin >> n;
    vector<int> socks(2*n);
    for(int i=0;i<2*n;i++)
    {
        cin >> socks[i];
    }
    if(n==1)
    {
        cout << "1";
        return 0;
    }
    map<int,int> mp;
    int answer = INT_MIN;

    for(int i=0;i<2*n;i+=2)
    {
        if(mp.find(socks[i])!=mp.end())
        {
            mp.erase(socks[i]);
        }
        else
        {
            mp.insert({socks[i],1});
        }
        if(mp.find(socks[i+1])!=mp.end())
        {
            mp.erase(socks[i+1]);
        }
        else
        {
            mp.insert({socks[i+1],1});
        }
        cout << mp.size() << "\n";
        answer = maxi(answer, mp.size());
    }

    cout << answer;
    return 0;
}


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

int maxi(int a,int b)
{
    if(a < b)
    {
        return b;
    }
    return a;
}

int main()
{
    int n;
    cin >> n;
    vector<int> socks(2*n);
    for(int i=0;i<2*n;i++)
    {
        cin >> socks[i];
    }
    if(n==1)
    {
        cout << "1";
        return 0;
    }
    map<int,int> mp;
    int answer = INT_MIN;

    for(int i=0;i<2*n;i+=2)
    {
        if(mp.find(socks[i])!=mp.end())
        {
            mp.erase(socks[i]);
        }
        else
        {
            mp.insert({socks[i],1});
        }
        if(mp.find(socks[i+1])!=mp.end())
        {
            mp.erase(socks[i+1]);
        }
        else
        {
            mp.insert({socks[i+1],1});
        }
        answer = maxi(answer, mp.size());
    }

    cout << answer;
    return 0;
}


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

int maxi(int a,int b)
{
    if(a < b)
    {
        return b;
    }
    return a;
}

int main()
{
    int n;
    cin >> n;
    vector<int> socks(2*n);
    for(int i=0;i<2*n;i++)
    {
        cin >> socks[i];
    }
    map<int,int> mp;
    int answer = INT_MIN;

    for(int i=0;i<2*n;i++)
    {
        if(mp.find(socks[i])!=mp.end())
        {
            mp.erase(socks[i]);
        }
        else
        {
            mp.insert({socks[i],1});
        }
        answer = maxi(answer, mp.size());
    }

    cout << answer;
    return 0;
}


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

bool chk[100005];

int main()
{
    int n;

    cin >> n;

    int a[200005], sum = 0, ans = 0;

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

        if(chk[a[i]]) ans = max(sum, ans), sum--;
        else sum++, chk[a[i]] = 1;
    }

    cout << ans << endl;

    return 0;
}


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

int b[100009];

int main()
{
    int n, i, sum = 0, ans = 0;

    cin >> n;

    int a[n + 5];

    for(i = 1; i <= (2 * n); i++){
        cin >> a[i];

        b[a[i]]++;
        sum++;

        if(b[a[i]] == 2){
            ans = max(ans, (sum - 1));
            sum -= 2;
        }
    }

    cout << ans << endl;

    return 0;
}


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

int main()
{
    int n, i, sum = 0;
    vector < int > a;

    cin >> n >> i;

    a.push_back(0);

    for(i = 1; i < n; i++){
        int x;
        cin >> x;
        a.push_back(x);

        if(a[i] == a[i - 1]) sum++;
    }

    cout << n - sum << endl;

    return 0;
}


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

bool chk[maxn];

int main()
{
    int n, x;

    cin >> n;

    int ans = 0, sum = 0;

    for(int i = 0; i < 2 * n; i++){
        cin >> x;

        if(chk[x]) sum--;
        else sum++;

        chk[x] = 1;
        ans = max(ans, sum);
    }

    cout << ans << endl;

    return 0;
}


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

int b[100009];

int main()
{
    int n, i, sum = 0, ans = 0;

    cin >> n;

    int a[(2 * n) + 5];

    for(i = 1; i <= (2 * n); i++){
        cin >> a[i];

        b[a[i]]++;
        sum++;

        if(b[a[i]] == 2){
            ans = max(ans, (sum - 1));
            sum -= 2;
        }
    }

    cout << ans << endl;

    return 0;
}


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

int main()
{
    int n, i, sum = 0;
    vector < int > a;

    cin >> n >> i;

    a.push_back(0);

    for(i = 1; i < (2 * n); i++){
        int x;
        cin >> x;
        a.push_back(x);

        if(a[i] == a[i - 1]) sum++;
    }

    cout << n - sum << endl;

    return 0;
}


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

int main()
{
    int n, i, sum = 0;
    vector < int > a;

    cin >> n >> i;

    a.push_back(i);

    for(i = 1; i < n; i++){
        int x;
        cin >> x;
        a.push_back(x);

        if(a[i] == a[i - 1]) sum++;
    }

    cout << n - sum << endl;

    return 0;
}


#include <bits/stdc++.h>

#define ll long long

using namespace std;

int const N = 2e5 + 1;

int main()
{
  int n;
  cin>>n;
  int arr[N];
  for (int i = 0; i < 2*n; ++i)
  {
    cin>>arr[i];
  }
  bool track[N];
  int count=0,tmp=0;
  for (int i = 0; i < 2*n; ++i)
  {
    if(!track[arr[i]])
    {
      track[arr[i]]=true;
      ++tmp;
    }
    else
      --tmp;
    count=max(count,tmp);
  }

  cout<<count<<endl;
}


#include <bits/stdc++.h>

#define ll long long

using namespace std;

int main()
{
  int n;
  cin>>n;
  int arr[2*n];
  for (int i = 0; i < 2*n; i++)
  {
    cin>>arr[i];
  }
  int count=1,max=1;
  for (int i = 1; i < 2*n; i++)
  {
    int flag=0;
    for (int j = i; j >0; j--)
    {
      if(arr[i]==arr[j-1])
      {
        count--;
        flag=1;
        break;
      }
    }
    if(flag==0)
      count++;
    if(count>=max)
      max=count;
  }
  cout<<max<<endl;
}


#include <bits/stdc++.h>

#define ll long long

using namespace std;

int main()
{
  int n;
  cin>>n;
  int arr[2*n];
  for (int i = 0; i < 2*n; ++i)
  {
    cin>>arr[i];
  }
  bool track[2*n];
  int count=0,tmp=0;
  for (int i = 0; i < 2*n; ++i)
  {
    if(!track[arr[i]])
    {
      track[arr[i]]=true;
      ++tmp;
    }
    else
      --tmp;
    count=max(count,tmp);
  }

  cout<<count<<endl;
}


#include <bits/stdc++.h>

#define ll long long

using namespace std;

int main()
{
  int n;
  cin>>n;
  int arr[2*n];
  for (int i = 0; i < 2*n; i++)
  {
    cin>>arr[i];
  }
  bool track[n];
  int count=0,tmp=0;
  for (int i = 0; i < 2*n; i++)
  {
    if(!track[arr[i]])
    {
      track[arr[i]]=true;
      tmp++;
    }
    else
      tmp--;
    count=max(count,tmp);
  }
  cout<<count<<endl;
}


#include <bits/stdc++.h>

#define ll long long

using namespace std;

int main()
{
  int n;
  cin>>n;
  int arr[2*n];
  for (int i = 0; i < 2*n; i++)
  {
    cin>>arr[i];
  }
  bool track[2*n];
  int count=0,tmp=0;
  for (int i = 0; i < 2*n; i++)
  {
    if(!track[arr[i]-1])
    {
      track[arr[i]-1]=true;
      tmp++;
    }
    else
      tmp--;
    count=max(count,tmp);
  }
  cout<<count<<endl;
}


#include <bits/stdc++.h>

#define ll long long

using namespace std;

int main()
{
  int n;
  cin>>n;
  int arr[2*n];
  for (int i = 0; i < 2*n; i++)
  {
    cin>>arr[i];
  }
  bool track[n];
  int count=0,tmp=0;
  for (int i = 0; i < 2*n; ++i)
  {
    if(!track[arr[i]])
    {
      track[arr[i]]=true;
      ++tmp;
    }
    else
      --tmp;
    count=max(count,tmp);
  }
  cout<<count<<endl;
}


#include <bits/stdc++.h>

#define ll long long

using namespace std;

int main()
{
  int n;
  cin>>n;
  int arr[2*n];
  for (int i = 0; i < 2*n; i++)
  {
    cin>>arr[i];
  }
  bool track[2*n];
  int count=0,tmp=0;
  for (int i = 0; i < 2*n; i++)
  {
    if(!track[arr[i]-1])
    {
      track[arr[i]-1]=true;
      tmp++;
    }
    else
      tmp--;
    count=max(count,tmp);
  }

  cout<<count<<endl;
}


#include <bits/stdc++.h>

#define ll long long

using namespace std;

int main()
{
  int n;
  cin>>n;
  int arr[2*n];
  for (int i = 0; i < 2*n; i++)
  {
    cin>>arr[i];
  }
  bool track[2*n];
  int count=0,tmp=0;
  for (int i = 0; i < 2*n; i++)
  {
    if(!track[arr[i]])
    {
      track[arr[i]]=true;
      tmp++;
    }
    else
      tmp--;
    count=max(count,tmp);
  }
  cout<<count<<endl;
}


#include <bits/stdc++.h>

#define ll long long

using namespace std;

int main()
{
  int n;
  cin>>n;
  int arr[2*n];
  for (int i = 0; i < 2*n; i++)
  {
    cin>>arr[i];
  }
  bool track[2*n];
  int count=0,tmp=0;
  for (int i = 0; i < 2*n; i++)
  {
    if(!track[arr[i]])
    {
      track[arr[i]]=true;
      tmp++;
    }
    else
      tmp++;
    count=max(count,tmp);
  }
  cout<<count<<endl;
}


#include<bits/stdc++.h>

using namespace std;

#define ll long long

int main() {
	int n;
	cin >> n;
	vector<bool> a(n + 1);
	memset(a, 0, sizeof(a));
	ll ans =0, high =0;
	for(int i = 0; i < n; ++i) {
		ll b;
		cin >> b;
		if (a[b] == 0) {
			++high;
			a[b] = 1;
		} else {
			a[b] = 0;
			--high;
		}
		ans = max(high, ans);
	}
	cout << ans << "\n";
}


#include<bits/stdc++.h>

using namespace std;

#define ll long long

int main() {
	int n;
	cin >> n;
	int ans = 0, high =0;
	bool a[100001];
	memset(a, 0, sizeof(a));
	for(int i = 0; i < n * 2; ++i) {
		int b;
		cin >> b;
		if (a[b] == 1) {
			--high;
			a[b] = 0;
		} else {
			a[b] = 1;
			++high;
		}
		ans = max(ans, high);
	}
	cout << ans << "\n";
}


#include<bits/stdc++.h>

using namespace std;

#define ll long long

int main() {
	int n;
	cin >> n;
	bool a[100001];
	memset(a, 0, sizeof(a));
	ll ans =0, high =0;
	for(int i = 0; i < n; ++i) {
		ll b;
		cin >> b;
		if (a[b] == 0) {
			++high;
			a[b] = 1;
		} else {
			a[b] = 0;
			--high;
		}
		ans = max(high, ans);
	}
	cout << ans << "\n";
}


#include<bits/stdc++.h>

using namespace std;

#define ll long long

int main() {
	int n;
	cin >> n;
	vector<int> a(n + 1);
	for(int i = 1; i <= n; ++i) {
		a[i] = 0;
	}
	ll ans =0, high =0;
	for(int i = 0; i < n; ++i) {
		ll b;
		cin >> b;
		if (a[b] == 0) {
			++high;
			a[b] = 1;
		} else {
			a[b] = 0;
			--high;
		}
		ans = max(high, ans);
	}
	cout << ans << "\n";
}


#include<bits/stdc++.h>

using namespace std;

#define ll long long

int main() {
	int n;
	cin >> n;
	bool a[100001];
	memset(a, 0, sizeof(a));
	int ans =0, high =0;
	for(int i = 0; i < n; ++i) {
		int b;
		cin >> b;
		if (a[b] == 0) {
			++high;
			a[b] = 1;
		} else {
			a[b] = 0;
			--high;
		}
		ans = max(high, ans);
	}
	cout << ans << "\n";
}


#include<bits/stdc++.h>

using namespace std;

#define ll long long

int main() {
	ll n;
	cin >> n;
	vector<ll> a(n + 1);
	for(ll i = 1; i <= n; ++i) {
		a[i] = 0;
	}
	ll ans =0, high =0;
	for(ll i = 0; i < n; ++i) {
		ll b;
		cin >> b;
		if (a[b] == 0) {
			++high;
			a[b] = 1;
		} else {
			a[b] = 0;
			--high;
		}
		ans = max(high, ans);
	}
	cout << ans << "\n";
}


#include<bits/stdc++.h>

using namespace std;

#define ll long long

int main() {
	int n;
	cin >> n;
	vector<bool> a(n + 1);
	for(int i = 1; i <= n; ++i) {
		a[i] = 0;
	}
	ll ans =0, high =0;
	for(int i = 0; i < n; ++i) {
		ll b;
		cin >> b;
		if (a[b] == 0) {
			++high;
			a[b] = 1;
		} else {
			a[b] = 0;
			--high;
		}
		ans = max(high, ans);
	}
	cout << ans << "\n";
}


#include<bits/stdc++.h>
bool stock[200005]={0};
int main()
{
    int ans=0,cnt=0;
    int n,in;
    scanf("%d",&n);
    for(int i=1;i<=n×2;i++){
        scanf("%d",&in);
        if(stock[in]==0){
            stock[in]=1;
            cnt++;
            ans=(ans>cnt)?ans:cnt;
        }
        else{
            stock[in]=0;
            cnt--;
        }
    }
    printf("%d",ans);

    return 0;
}


#include <cstdio>

int main()
{
    unsigned n, m;
    bool table[150000] = {0};
    unsigned count = 0;
    unsigned max_count = 0;

    scanf("%u", &n);

    for (unsigned i = 0; i != n * 2; ++i)
    {
        scanf("%d", &m);
        if (table[m])
        {
            --count;
            table[m] = false;
        }
        else
        {
            ++count;
            if (count > max_count)
                max_count = count;
            table[m] = true;
        }
    }

    printf("%u\n", max_count);

    return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;
int a[20005];
int b[10005];
int main()
{
	int n,i;
	cin>>n;
	int count=0;
	int temp;
	int maax=-1;
	for(i=1;i<=2*n;i++)
	{
		cin>>a[i];
		temp=++b[a[i]];
		//cout<<"temp="<<temp<<endl;
		if(temp==1)
		{
			count++;
			maax=max(count,maax);
			//cout<<"maax="<<maax<<endl;
		}
		if(temp==2)
		{
			count--;
			maax=max(count,maax);
		}
	}
	cout<<maax;
	return 0;
}


#include<iostream>
#include<cstdio>
#include<stack>
#include<set>
using namespace std;
int mx;
set<int> table;
int main(){
	int n,x;
	cin>>n;
	mx=0;
	for(int j=0;j<2*n;j++){
		scanf("%d",&x);
		if(table.count(x)==1)table.erase(x);
		else table.insert(x);
		//cout<<table.size()<<endl;
		if(mx<=table.size())mx=table.size();
	}
	cout<<mx<<endl;
	return 0;
}


#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
using namespace std;

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

unordered_set<int, custom_hash> st;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    int n, maxx = -INF, cnt = 0;
    cin >> n;
    for (int i = 0; i < n * 2; ++i) {
        int t;
        cin >> t;
        if (st.count(t))
            cnt--;
        else {
            st.insert(t);
            ++cnt;
            maxx = max(cnt, maxx);
        }
        //cout << cnt << ", " << maxx << endl;
    }
    cout << maxx << endl;
    return 0;
}


#include <iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
#include<bitset>

using namespace std;

#define ll long long

int main()
{
//freopen("a.in","r",stdin);
    ll n,x,c=0,maxxx=0;
    set <ll> st;
    cin>>n;
    n*=2;
    while(n--)
    {
        cin>>x;
        if(st.find(x) != st.end())
        {
            c--;
        }
        else
        {
            st.insert(x);
            c++;
        }
        if(c>maxxx)
        {
            maxxx=c;
        }
    }
    cout<<maxxx;
    return 0;
}


#include <iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
#include<bitset>

using namespace std;

#define ll long long

int main()
{
//freopen("a.in","r",stdin);
    ll n,x,c=0,maxxx=0;
    set <ll> st;
    cin>>n;
    while(n--)
    {
        cin>>x;
        if(st.find(x) != st.end())
        {
            c--;
        }
        else
        {
            st.insert(x);
            c++;
        }
        if(c>maxxx)
        {
            maxxx=c;
        }
    }
    cout<<maxxx;
    return 0;
}


#include <iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
#include<bitset>

using namespace std;

#define ll long long

int main()
{
//freopen("a.in","r",stdin);
    ll n,x,c=0,maxxx=0;
    set <ll> st;
    cin>>n;
    while(n--)
    {
        cin>>x;
        if(st.find(x) != st.end())
        {
            c--;
        }
        else
        {
            st.insert(x);
            c++;
        }
        if(st.size()>maxxx)
        {
            maxxx=st.size();
        }
    }
    cout<<st.size();
    return 0;
}


#include <iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
#include<bitset>

using namespace std;

#define ll long long

int main()
{
//freopen("a.in","r",stdin);
    long n,x,c=0,maxxx=0;
    set <int> st;
    cin>>n;
    while(n--)
    {
        cin>>x;
        if(st.find(x) != st.end())
        {
            c--;
        }
        else
        {
            st.insert(x);
            c++;
        }
        if(st.size()>maxxx)
        {
            maxxx=st.size();
        }
    }
    cout<<st.size();
    return 0;
}


#include <iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
#include<bitset>

using namespace std;

#define ll long long

int main()
{
//freopen("a.in","r",stdin);
    ll n,x,c=0,maxxx=0;
    set <ll> st;
    cin>>n;
    while(n--)
    {
        cin>>x;
        if(st.find(x) != st.end())
        {
            c--;
        }
        else
        {
            st.insert(x);
            c++;
        }
        if(st.size()>maxxx)
        {
            maxxx=st.size();
        }
    }
    cout<<maxxx;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
long long magida, mux, c,socks, i, j;
int windebi[100001];

int main(){
  set<int>stol;
  cin>>socks;
  for(i=0;i<socks;i++){
    cin>>windebi[i];
  }
  c=0;
  mux=0;
  magida=0;
  for(i=0;i<socks;i++){
    stol.insert(windebi[i]);
    if(c!=stol.size()){magida++;c=stol.size();if(magida>mux) {mux=magida;}}
    else magida-=2;
  }
  cout<<mux;
}


#include<bits/stdc++.h>
using namespace std;
int magida, mux, c,socks, i, j,windebi[100001];

int main(){
  set<int>stol;
  cin>>socks;
  for(i=0;i<socks;i++){
    cin>>windebi[i];
  }
  c=0;
  mux=0;
  magida=0;
  for(i=0;i<socks;i++){
    stol.insert(windebi[i]);
    if(c!=stol.size()){magida++;c=stol.size();if(magida>mux) {mux=magida;}}
    else magida--;
  }
  cout<<mux;
}


#include<bits/stdc++.h>
using namespace std;
long long magida, mux, c,socks, i, j;
int windebi[200001];

int main(){
  set<int>stol;
  cin>>socks;
  for(i=0;i<2*socks;i++){
    cin>>windebi[i];
  }
  c=0;
  mux=0;
  magida=0;
  for(i=0;i<2*socks;i++){
    stol.insert(windebi[i]);
    if(c!=stol.size()){magida++;c=stol.size();}
    else magida--;
    if(magida>mux) {mux=magida;}
  }
  cout<<mux;
}


#include<bits/stdc++.h>
using namespace std;
long long magida, mux, c,socks, i, j;
int windebi[100001];

int main(){
  set<int>stol;
  cin>>socks;
  for(i=0;i<socks;i++){
    cin>>windebi[i];
  }
  c=0;
  mux=0;
  magida=0;
  for(i=0;i<socks;i++){
    stol.insert(windebi[i]);
    if(c!=stol.size()){magida++;c=stol.size();if(magida>mux) {mux=magida;}}
    else magida--;
  }
  cout<<mux;
}


#include<bits/stdc++.h>
using namespace std;
long long magida, mux, c,socks, i, j;
int windebi[100001];

int main(){
  set<int>stol;
  cin>>socks;
  for(i=0;i<2*socks;i++){
    cin>>windebi[i];
  }
  c=0;
  mux=0;
  magida=0;
  for(i=0;i<2*socks;i++){
    stol.insert(windebi[i]);
    if(c!=stol.size()){magida++;c=stol.size();}
    else magida--;
    if(magida>mux) {mux=magida;}
  }
  cout<<mux;
}


#include<iostream>
using namespace std;
int main()
{
int    p,q=0,max=0,n,i;
    cin>>p;
    n=p*2;
    bool H[99999*2]={0};
    for(i=0;i<n;i++)
    {
        cin>>p;
        if(H[p]==0)
        {
            H[p]=1;
            q++;
        }
        else
        {
            H[p]=0;
            q--;
        }
        if(max < q)
            max=q;
    }
    cout<<max;

}


#include<iostream>
using namespace std;
int size(int *a,int n)
{
int i,c=0;
for(i=0;i<n;i++)
{
    if(a[i]>0)
        c++;
}
return c;
}
int main()
{
    int n,p,*b,*t,i,max=0,c,j;
    cin>>p;
    n=p*2;
    b=new int[n];
    t=new int[n];
    for(i=0;i<n;i++)
    {
        cin>>b[i];
        t[i]=0;
    }
    for(i=0;i<n;i++)
    {
        for(j=0;j<n;j++)
        {
            if(t[j]==0)
            {
                t[j]=b[i];
                break;
            }
            else if(t[j]==b[i])
            {
                t[j]=-1;
                break;
            }

        }
        c=size(t,n);
        if(max<c)
            max=c;
    }
    cout<<max;
}


#include<iostream>
using namespace std;
int main()
{
    int p,q=0,max=0,n,i;
    cin>>p;
    n=p*2;
    bool H[10001]={0};
    for(i=0;i<n;i++)
    {
        cin>>p;
        if(H[p]==0)
        {
            H[p]=1;
            q++;
        }
        else
        {
            H[p]=0;
            q--;
        }
        if(max < q)
            max=q;
    }
    cout<<max;

}