#include<iostream>
#include <bits/stdc++.h>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long int into;
#define w 1000000007;
vector<int>comp;

void dfs(int v,vector<vector<int>>adj,bool used[]) {
    used[v] = true ;
    comp.push_back(v);
    for (int i = 0; i < adj[v].size(); ++i) {
        int to = adj[v][i];
        if (!used[to])
            dfs(to,adj,used);
    }
}

void find_comps(vector<vector<int>>adj,int a[],int n) {
  bool used[n+1];

  int count=0;
    for (int i = 1; i < n+1 ; ++i)
        used [i] = false;

    for (int i = 1; i < n+1 ; ++i)
        {
          if (!used[i]) {
            comp.clear();
            dfs(i,adj,used);
            int min=a[comp[0]-1];

            for(size_t z=0;z<comp.size();z++)
            { if(a[comp[z]-1]<min)
              min=a[comp[z]-1];
            } /*cout<<i<<" "<<min<<endl;*/
             count+=min;

} }cout<<count<<endl;
}

void bfs(vector< vector<int> >adj,int s,int n)
 {
  queue<int>q;
  vector<bool>vis(n+1,false);
  vector<int>parent(n+1);

 parent[s]=0;
 q.push(s);

 vis[s]=true;

 while(!q.empty())
 {

   int v=q.front();
   q.pop();
   for( int u:adj[v])
   {
      if(!vis[u])
      {
         parent[u]=v;
         q.push(u);
        vis[u]=true;
         }

     }

  }   for(int i=2;i<n;i++)
      if(!vis[i])
      {
        cout<<"NO"<<endl;
        return;
      }
     cout<<"YES"<<endl;

   for(int i=2;i<=n;i++)
      cout<<parent[i]<<" "<<i<<endl;
/*if(!vis[n])
  cout<<"NO";
else
{ vector<int>path;

  for(int l=n;parent[l]!=0;l=parent[l])
    path.push_back(l);
  reverse(path.begin(),path.end());
  cout<<"YES"<<endl<<path.size()+1<<endl;
  cout<<s<<" ";
  for(int i:path)
    cout<<i<<" ";*/
}

int main() {
  /*#ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
  freopen("out1.txt","w",stdout);
  #endif*/

ios_base::sync_with_stdio (false);
 int n,m;
  cin>>n>>m;
  vector<vector<int>>adj(n+1);

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

} if(!sum)
find_comps(adj,a,n);
else cout<<"0"<<endl;
}


#include<iostream>
#include <bits/stdc++.h>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long int into;
#define w 1000000007;

void dfs(int v,vector<vector<int>>adj,bool used[]) {
    used[v] = true ;

    for (int i = 0; i < adj[v].size(); ++i) {
        int to = adj[v][i];
        if (!used[to])
            dfs(to,adj,used);
    }
}

void find_comps(vector<vector<int>>adj,vector<pair<int,int>>price,int n) {
  bool used[n+1];

  int count=0;
    for (int i = 0; i < n ; ++i)
        used [price[i].second] = false;

    for (int i = 0; i < n ; ++i)
        {
          if (!used[price[i].second]) {
            dfs(price[i].second,adj,used);
            count+=price[i].first;

} }cout<<count<<endl;
}

void bfs(vector< vector<int> >adj,int s,int n)
 {
  queue<int>q;
  vector<bool>vis(n+1,false);
  vector<int>parent(n+1);

 parent[s]=0;
 q.push(s);

 vis[s]=true;

 while(!q.empty())
 {

   int v=q.front();
   q.pop();
   for( int u:adj[v])
   {
      if(!vis[u])
      {
         parent[u]=v;
         q.push(u);
        vis[u]=true;
         }

     }

  }   for(int i=2;i<n;i++)
      if(!vis[i])
      {
        cout<<"NO"<<endl;
        return;
      }
     cout<<"YES"<<endl;

   for(int i=2;i<=n;i++)
      cout<<parent[i]<<" "<<i<<endl;
/*if(!vis[n])
  cout<<"NO";
else
{ vector<int>path;

  for(int l=n;parent[l]!=0;l=parent[l])
    path.push_back(l);
  reverse(path.begin(),path.end());
  cout<<"YES"<<endl<<path.size()+1<<endl;
  cout<<s<<" ";
  for(int i:path)6 5

    cout<<i<<" ";*/
}

int main() {
  /*#ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
  freopen("out1.txt","w",stdout);
  #endif */

ios_base::sync_with_stdio (false);
 int n,m,x,y;
  cin>>n>>m;

  vector<vector<int>>adj(n);
  vector<pair<int,int>>price;
  for (int i = 0; i < n; ++i)
  {  cin>>x;
    price.push_back(make_pair(x,i));
  }
 sort(price.begin(),price.end());
 /*for (int i = 0; i < n; ++i)
 {
   cout<<price[i].first<<" "<<price[i].second<<endl;
 }*/

while(m--)
  { cin>>x>>y;
    adj[x-1].push_back(y-1);
    adj[y-1].push_back(x-1);

}

   find_comps(adj,price,n);

     }


#include<iostream>
#include <bits/stdc++.h>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long int into;
#define w 1000000007;
vector<int>comp;

void dfs(int v,vector<vector<int>>adj,bool used[]) {
    used[v] = true ;
    comp.push_back(v);
    for (int i = 0; i < adj[v].size(); ++i) {
        int to = adj[v][i];
        if (!used[to])
            dfs(to,adj,used);
    }
}

void find_comps(vector<vector<int>>adj,int a[],int n) {
  bool used[n+1];

  int count=0;
    for (int i = 1; i < n+1 ; ++i)
        used [i] = false;

    for (int i = 1; i < n+1 ; ++i)
        {
          if (!used[i]) {
            comp.clear();
            dfs(i,adj,used);
            int min=a[comp[0]-1];

            for(size_t z=0;z<comp.size();z++)
            { if(a[comp[z]-1]<min)
              min=a[comp[z]-1];
            } /*cout<<i<<" "<<min<<endl;*/
             count+=min;

} }cout<<count<<endl;
}

void bfs(vector< vector<int> >adj,int s,int n)
 {
  queue<int>q;
  vector<bool>vis(n+1,false);
  vector<int>parent(n+1);

 parent[s]=0;
 q.push(s);

 vis[s]=true;

 while(!q.empty())
 {

   int v=q.front();
   q.pop();
   for( int u:adj[v])
   {
      if(!vis[u])
      {
         parent[u]=v;
         q.push(u);
        vis[u]=true;
         }

     }

  }   for(int i=2;i<n;i++)
      if(!vis[i])
      {
        cout<<"NO"<<endl;
        return;
      }
     cout<<"YES"<<endl;

   for(int i=2;i<=n;i++)
      cout<<parent[i]<<" "<<i<<endl;
/*if(!vis[n])
  cout<<"NO";
else
{ vector<int>path;

  for(int l=n;parent[l]!=0;l=parent[l])
    path.push_back(l);
  reverse(path.begin(),path.end());
  cout<<"YES"<<endl<<path.size()+1<<endl;
  cout<<s<<" ";
  for(int i:path)
    cout<<i<<" ";*/
}

int main() {
  /*#ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
  freopen("out1.txt","w",stdout);
  #endif*/

ios_base::sync_with_stdio (false);
 int n,m;
  cin>>n>>m;
  vector<vector<int>>adj(n+1);

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

}
find_comps(adj,a,n);
}


#include<iostream>
#include <bits/stdc++.h>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long int into;
#define w 1000000007;
vector<int>comp;

void dfs(int v,vector<vector<int>>adj,bool used[]) {
    used[v] = true ;
    comp.push_back(v);
    for (int i = 0; i < adj[v].size(); ++i) {
        int to = adj[v][i];
        if (!used[to])
            dfs(to,adj,used);
    }
}

void find_comps(vector<vector<int>>adj,int a[],int n) {
  bool used[n+1];

  int count=0;
    for (int i = 1; i < n+1 ; ++i)
        used [i] = false;

    for (int i = 1; i < n+1 ; ++i)
        {
          if (!used[i]) {
            comp.clear();
            dfs(i,adj,used);
            int min=a[comp[0]-1];

            for(size_t z=0;z<comp.size();z++)
            { if(a[comp[z]-1]<min)
              min=a[comp[z]-1];
            } /*cout<<i<<" "<<min<<endl;*/
             count+=min;

} }cout<<count<<endl;
}

void bfs(vector< vector<int> >adj,int s,int n)
 {
  queue<int>q;
  vector<bool>vis(n+1,false);
  vector<int>parent(n+1);

 parent[s]=0;
 q.push(s);

 vis[s]=true;

 while(!q.empty())
 {

   int v=q.front();
   q.pop();
   for( int u:adj[v])
   {
      if(!vis[u])
      {
         parent[u]=v;
         q.push(u);
        vis[u]=true;
         }

     }

  }   for(int i=2;i<n;i++)
      if(!vis[i])
      {
        cout<<"NO"<<endl;
        return;
      }
     cout<<"YES"<<endl;

   for(int i=2;i<=n;i++)
      cout<<parent[i]<<" "<<i<<endl;
/*if(!vis[n])
  cout<<"NO";
else
{ vector<int>path;

  for(int l=n;parent[l]!=0;l=parent[l])
    path.push_back(l);
  reverse(path.begin(),path.end());
  cout<<"YES"<<endl<<path.size()+1<<endl;
  cout<<s<<" ";
  for(int i:path)
    cout<<i<<" ";*/
}

int main() {
  /*#ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
  freopen("out1.txt","w",stdout);
  #endif */

ios_base::sync_with_stdio (false);
 int n,m;
  cin>>n>>m;
  vector<vector<int>>adj(n+1);

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

} if(sum!=0)
find_comps(adj,a,n);
else cout<<"0"<<endl;
}


#include<iostream>
#include <bits/stdc++.h>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long int into;
#define w 1000000007;

void dfs(int v,vector<vector<int>>adj,bool used[]) {
    used[v] = true ;

    for (int i = 0; i < adj[v].size(); ++i) {
        int to = adj[v][i];
        if (!used[to])
            dfs(to,adj,used);
    }
}

void find_comps(vector<vector<int>>adj,map<int,int>price,int n) {
  bool used[n+1];

  int count=0;
    for (auto u:price)
        used [u.second] = false;

    for (auto u:price)
        {
          if (!used[u.second]) {
            dfs(u.second,adj,used);
            count+=u.first;

} }cout<<count<<endl;
}

void bfs(vector< vector<int> >adj,int s,int n)
 {
  queue<int>q;
  vector<bool>vis(n+1,false);
  vector<int>parent(n+1);

 parent[s]=0;
 q.push(s);

 vis[s]=true;

 while(!q.empty())
 {

   int v=q.front();
   q.pop();
   for( int u:adj[v])
   {
      if(!vis[u])
      {
         parent[u]=v;
         q.push(u);
        vis[u]=true;
         }

     }

  }   for(int i=2;i<n;i++)
      if(!vis[i])
      {
        cout<<"NO"<<endl;
        return;
      }
     cout<<"YES"<<endl;

   for(int i=2;i<=n;i++)
      cout<<parent[i]<<" "<<i<<endl;
/*if(!vis[n])
  cout<<"NO";
else
{ vector<int>path;

  for(int l=n;parent[l]!=0;l=parent[l])
    path.push_back(l);
  reverse(path.begin(),path.end());
  cout<<"YES"<<endl<<path.size()+1<<endl;
  cout<<s<<" ";
  for(int i:path)6 5

    cout<<i<<" ";*/
}

int main() {
  /*#ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
  freopen("out1.txt","w",stdout);
  #endif */

ios_base::sync_with_stdio (false);
 int n,m,x,y;
  cin>>n>>m;

  vector<vector<int>>adj(n);
  map<int,int>price;
  for (int i = 0; i < n; ++i)
  {  cin>>x;
    price.insert(pair<int,int>(x,i));
  }

while(m--)
  { cin>>x>>y;
    adj[x-1].push_back(y-1);
    adj[y-1].push_back(x-1);

}

   find_comps(adj,price,n);

     }


#include<iostream>
#include <bits/stdc++.h>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long int into;
#define w 1000000007;
vector<int>comp;

void dfs(int v,vector<vector<int>>adj,bool used[]) {
    used[v] = true ;
    comp.push_back(v);
    for (int i = 0; i < adj[v].size(); ++i) {
        int to = adj[v][i];
        if (!used[to])
            dfs(to,adj,used);
    }
}

void find_comps(vector<vector<int>>adj,int a[],int n) {
  bool used[n+1];

  int count=0;
    for (int i = 1; i < n+1 ; ++i)
        used [i] = false;

    for (int i = 1; i < n+1 ; ++i)
        {
          if (!used[i]) {
            comp.clear();
            dfs(i,adj,used);
            int min=a[comp[0]-1];

            for(int z=0;z<comp.size();z++)
            { if(a[comp[z]-1]<min)
              min=a[comp[z]-1];
            } /*cout<<i<<" "<<min<<endl;*/
             count+=min;

} }cout<<count<<endl;
}

void bfs(vector< vector<int> >adj,int s,int n)
 {
  queue<int>q;
  vector<bool>vis(n+1,false);
  vector<int>parent(n+1);

 parent[s]=0;
 q.push(s);

 vis[s]=true;

 while(!q.empty())
 {

   int v=q.front();
   q.pop();
   for( int u:adj[v])
   {
      if(!vis[u])
      {
         parent[u]=v;
         q.push(u);
        vis[u]=true;
         }

     }

  }   for(int i=2;i<n;i++)
      if(!vis[i])
      {
        cout<<"NO"<<endl;
        return;
      }
     cout<<"YES"<<endl;

   for(int i=2;i<=n;i++)
      cout<<parent[i]<<" "<<i<<endl;
/*if(!vis[n])
  cout<<"NO";
else
{ vector<int>path;

  for(int l=n;parent[l]!=0;l=parent[l])
    path.push_back(l);
  reverse(path.begin(),path.end());
  cout<<"YES"<<endl<<path.size()+1<<endl;
  cout<<s<<" ";
  for(int i:path)
    cout<<i<<" ";*/
}

int main() {
  #ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
  freopen("out1.txt","w",stdout);
  #endif

ios_base::sync_with_stdio (false);
 int n,m;
  cin>>n>>m;
  vector<vector<int>>adj(n+1);

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

}
find_comps(adj,a,n);
}


#include<iostream>
#include <bits/stdc++.h>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long int into;
#define w 1000000007;
vector<int>comp;
void swap(int* a, int* b)
{
    int t = *a;
    *a = *b;
    *b = t;
}

/* This function takes last element as pivot, places
the pivot element at its correct position in sorted
array, and places all smaller (smaller than pivot)
to left of pivot and all greater elements to right
of pivot */
int partition (int arr[],int brr[], int low, int high)
{
    int pivot = arr[high]; // pivot
    int i = (low - 1); // Index of smaller element

    for (int j = low; j <= high - 1; j++)
    {
        // If current element is smaller than the pivot
        if (arr[j] < pivot)
        {
            i++; // increment index of smaller element
            swap(&brr[i], &brr[j]);
        }
    }
    swap(&brr[i + 1], &brr[high]);
    return (i + 1);
}

/* The main function that implements QuickSort
arr[] --> Array to be sorted,
low --> Starting index,
high --> Ending index */
void quickSort(int arr[],int brr[], int low, int high)
{
    if (low < high)
    {
        /* pi is partitioning index, arr[p] is now
        at right place */
        int pi = partition(arr,brr, low, high);

        // Separately sort elements before
        // partition and after partition
        quickSort(arr,brr, low, pi - 1);
        quickSort(arr,brr, pi + 1, high);
    }
}

void dfs(int v,vector<vector<int>>adj,bool used[]) {
    used[v] = true ;

    for (int i = 0; i < adj[v].size(); ++i) {
        int to = adj[v][i];
        if (!used[to])
            dfs(to,adj,used);
    }
}

void find_comps(vector<vector<int>>adj,int a[],int price[],int n) {
  bool used[n+1];

  int count=0;
    for (int i = 0; i < n ; ++i)
        used [a[i]] = false;

    for (int i = 0; i < n ; ++i)
        {
          if (!used[a[i]]) {
            dfs(a[i],adj,used);
            count+=price[a[i]];

} }cout<<count<<endl;
}

void bfs(vector< vector<int> >adj,int s,int n)
 {
  queue<int>q;
  vector<bool>vis(n+1,false);
  vector<int>parent(n+1);

 parent[s]=0;
 q.push(s);

 vis[s]=true;

 while(!q.empty())
 {

   int v=q.front();
   q.pop();
   for( int u:adj[v])
   {
      if(!vis[u])
      {
         parent[u]=v;
         q.push(u);
        vis[u]=true;
         }

     }

  }   for(int i=2;i<n;i++)
      if(!vis[i])
      {
        cout<<"NO"<<endl;
        return;
      }
     cout<<"YES"<<endl;

   for(int i=2;i<=n;i++)
      cout<<parent[i]<<" "<<i<<endl;
/*if(!vis[n])
  cout<<"NO";
else
{ vector<int>path;

  for(int l=n;parent[l]!=0;l=parent[l])
    path.push_back(l);
  reverse(path.begin(),path.end());
  cout<<"YES"<<endl<<path.size()+1<<endl;
  cout<<s<<" ";
  for(int i:path)6 5

    cout<<i<<" ";*/
}

int main() {
  /*#ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
  freopen("out1.txt","w",stdout);
  #endif */

ios_base::sync_with_stdio (false);
 int n,m;
  cin>>n>>m;
  int price[n];
  vector<vector<int>>adj(n);
  int a[n];
  for (int i = 0; i < n; ++i)
  {
    a[i]=i;
  }
  for (int i = 0; i < n; ++i)
  {
    cin>>price[i];
  } int x,y;
while(m--)
  { cin>>x>>y;
    adj[x-1].push_back(y-1);
    adj[y-1].push_back(x-1);

}
   quickSort(price,a,0,n-1);
   find_comps(adj,a,price,n);

     }


#include <bits/stdc++.h>
using namespace std;
vector<vector<long long> >graph;
bool flag[100006];
void dfs(long long n){
    flag[n]=1;
    for(long long i=0;i<graph[n].size();i++){
        if(!flag[graph[n][i]]){
            dfs(graph[n][i]);
        }
    }
}
int main() {
    long long n,m;
    cin>>n>>m;
    graph.resize(n+1);
    long long t[n+1],k=m;
    for(long long i=1;i<=n;i++){
        cin>>t[i];
    }
    while(m--){
        long long x,y;
        cin>>x>>y;
        graph[x].push_back(y);
        graph[y].push_back(x);
    }
    long long gold=0;
    for(long long i=1;i<=n;i++){
        if(k>0&&!flag[i]&&t[i]>=0){
            dfs(i);
            long long amount=t[i];
            for(long long j=0;j<graph[i].size();j++){
                if(t[graph[i][j]]<amount){
                    amount=t[graph[i][j]];
                }
                t[graph[i][j]]=-1;
            }
            t[i]=-1;
            gold+=amount;
            k--;
        }
    }
    for(long long i=1;i<=n;i++){
        if(!flag[i]){
            gold+=t[i];
        }
    }
    cout<<gold<<endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
vector<vector<int> >graph;
bool flag[100006];
void dfs(int n){
    flag[n]=1;
    for(int i=0;i<graph[n].size();i++){
        if(!flag[graph[n][i]]){
            dfs(graph[n][i]);
        }
    }
}
int main() {
    int n,m;
    cin>>n>>m;
    graph.resize(n+1);
    int t[n+1];
    for(int i=1;i<=n;i++){
        cin>>t[i];
    }
    while(m--){
        int x,y;
        cin>>x>>y;
        graph[x].push_back(y);
        graph[y].push_back(x);
    }
    int gold=0;
    for(int i=1;i<=n;i++){
        dfs(i);
        int amount=999999;
        for(int j=1;j<n+1;j++){
            if(flag[j]&&t[j]>=0){
                if(t[j]<amount){
                    amount=t[j];
                }
                t[j]=-1;
            }
        }
        if(amount!=999999){
            gold+=amount;
        }
    }
    cout<<gold<<endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
vector<vector<int> >graph;
bool flag[100006];
void dfs(int n){
    flag[n]=1;
    for(int i=0;i<graph[n].size();i++){
        if(!flag[graph[n][i]]){
            dfs(graph[n][i]);
        }
    }
}
int main() {
    int n,m;
    cin>>n>>m;
    graph.resize(n+1);
    int t[n+1],k=m;
    for(int i=1;i<=n;i++){
        cin>>t[i];
    }
    while(m--){
        int x,y;
        cin>>x>>y;
        graph[x].push_back(y);
        graph[y].push_back(x);
    }
    long long gold=0;
    for(int i=1;i<=n;i++){
        if(k>0&&!flag[i]){
            dfs(i);
            int amount=INT_MAX;
            for(int j=1;j<n+1;j++){
                if(flag[j]&&t[j]>=0){
                    if(t[j]<amount){
                        amount=t[j];
                    }
                    t[j]=-1;
                }
            }
            gold+=amount;
            k--;
        }
    }
    for(int i=1;i<=n;i++){
        if(!flag[i]){
            gold+=t[i];
        }
    }
    cout<<gold<<endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
vector<vector<long long> >graph;
bool flag[100006];
long long t[100006];
long long cal;
void dfs(long long n){
    flag[n]=1;
    cal=min(cal,t[n]);
    for(long long i=0;i<graph[n].size();i++){
        if(!flag[graph[n][i]]){
            dfs(graph[n][i]);
        }
    }
}
int main() {
    long long n,m;
    cin>>n>>m;
    graph.resize(n+1);
    for(long long i=1;i<=n;i++){
        cin>>t[i];
    }
    while(m--){
        long long x,y;
        cin>>x>>y;
        graph[x].push_back(y);
        graph[y].push_back(x);
    }
    long long gold=0;
    for(long long i=1;i<=n;i++){
        if(!flag[i]){
            cal=1999999999;
            dfs(i);
            gold+=cal;
        }
    }
    cout<<gold<<endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
vector<vector<int> >graph;
bool flag[100006];
void dfs(int n){
    flag[n]=1;
    for(int i=0;i<graph[n].size();i++){
        if(!flag[graph[n][i]]){
            dfs(graph[n][i]);
        }
    }
}
int main() {
    int n,m;
    cin>>n>>m;
    graph.resize(n+1);
    int t[n+1],k=m;
    for(int i=1;i<=n;i++){
        cin>>t[i];
    }
    while(m--){
        int x,y;
        cin>>x>>y;
        graph[x].push_back(y);
        graph[y].push_back(x);
    }
    long long gold=0;
    for(int i=1;i<=n;i++){
        if(k>0&&!flag[i]){
            dfs(i);
            int amount=t[i];
            for(int j=0;j<graph[i].size();j++){
                if(t[graph[i][j]]<amount){
                    amount=t[graph[i][j]];
                }
            }
            gold+=amount;
            k--;
        }
    }
    for(int i=1;i<=n;i++){
        if(!flag[i]){
            gold+=t[i];
        }
    }
    cout<<gold<<endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
vector<vector<int> >graph;
bool flag[100006];
void dfs(int n){
    flag[n]=1;
    for(int i=0;i<graph[n].size();i++){
        if(!flag[graph[n][i]]){
            dfs(graph[n][i]);
        }
    }
}
int main() {
    int n,m;
    cin>>n>>m;
    graph.resize(n+1);
    int t[n+1];
    for(int i=1;i<=n;i++){
        cin>>t[i];
    }
    while(m--){
        int x,y;
        cin>>x>>y;
        graph[x].push_back(y);
        graph[y].push_back(x);
    }
    int gold=0;
    for(int i=1;i<=n;i++){
        dfs(i);
        int amount=999999;
        for(int i=1;i<n+1;i++){
            if(flag[i]&&t[i]>=0){
                if(t[i]<amount){
                    amount=t[i];
                }
                t[i]=-1;
            }
        }
        if(amount!=999999){
            gold+=amount;
        }
    }
    cout<<gold<<endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
vector<vector<long long> >graph;
bool flag[100006];
void dfs(long long n){
    flag[n]=1;
    for(long long i=0;i<graph[n].size();i++){
        if(!flag[graph[n][i]]){
            dfs(graph[n][i]);
        }
    }
}
int main() {
    long long n,m;
    cin>>n>>m;
    graph.resize(n+1);
    long long t[n+1],k=m;
    map<long long,long long> mp;
    for(long long i=1;i<=n;i++){
        cin>>t[i];
    }
    while(m--){
        long long x,y;
        cin>>x>>y;
        mp[x]=y;
        mp[y]=x;
        graph[x].push_back(y);
        graph[y].push_back(x);
    }
    long long gold=0;
    for(long long i=1;i<=n;i++){
        if(k>0&&!flag[i]&&mp.find(i)!=mp.end()){
            dfs(i);
            long long amount=9999999999;
            for(long long j=0;j<graph[i].size();j++){
                if(t[graph[i][j]]<amount&&flag[graph[i][j]]&&t[graph[i][j]]>=0){
                    amount=t[graph[i][j]];
                }
                t[graph[i][j]]=-1;
            }
            if(t[i]<amount){
                amount=t[i];
            }
            t[i]=-1;
            gold+=amount;
            k--;
        }
    }
    for(long long i=1;i<=n;i++){
        if(!flag[i]){
            gold+=t[i];
        }
    }
    cout<<gold<<endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
vector<vector<long long> >graph;
bool flag[100006];
void dfs(long long n){
    flag[n]=1;
    for(long long i=0;i<graph[n].size();i++){
        if(!flag[graph[n][i]]){
            dfs(graph[n][i]);
        }
    }
}
int main() {
    long long n,m;
    cin>>n>>m;
    graph.resize(n+1);
    long long t[n+1],k=m;
    for(long long i=1;i<=n;i++){
        cin>>t[i];
    }
    while(m--){
        long long x,y;
        cin>>x>>y;
        graph[x].push_back(y);
        graph[y].push_back(x);
    }
    long long gold=0;
    for(long long i=1;i<=n;i++){
        if(k>0&&!flag[i]){
            dfs(i);
            long long amount=t[i];
            for(long long j=0;j<graph[i].size();j++){
                if(t[graph[i][j]]<amount&&flag[graph[i][j]]&&t[graph[i][j]]>=0){
                    amount=t[graph[i][j]];
                }
                t[graph[i][j]]=-1;
            }
            t[i]=-1;
            gold+=amount;
            k--;
        }
    }
    for(long long i=1;i<=n;i++){
        if(!flag[i]){
            gold+=t[i];
        }
    }
    cout<<gold<<endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
vector<vector<int> >graph;
bool flag[100006];
void dfs(int n){
    flag[n]=1;
    for(int i=0;i<graph[n].size();i++){
        if(!flag[graph[n][i]]){
            dfs(graph[n][i]);
        }
    }
}
int main() {
    int n,m;
    cin>>n>>m;
    graph.resize(n+1);
    int t[n+1],k=m;
    for(int i=1;i<=n;i++){
        cin>>t[i];
    }
    while(m--){
        int x,y;
        cin>>x>>y;
        graph[x].push_back(y);
        graph[y].push_back(x);
    }
    int gold=0;
    for(int i=1;i<=n;i++){
        if(k>0&&!flag[i]){
            dfs(i);
            int amount=999999;
            for(int j=1;j<n+1;j++){
                if(flag[j]&&t[j]>=0){
                    if(t[j]<amount){
                        amount=t[j];
                    }
                    t[j]=-1;
                }
            }
            gold+=amount;
            k--;
        }
    }
    for(int i=1;i<=n;i++){
        if(!flag[i]){
            gold+=t[i];
        }
    }
    cout<<gold<<endl;
    return 0;
}


#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <functional>
#include <algorithm>
#include <ctime>
#include <cmath>
#include <vector>
#include <unordered_map>
using namespace std;

int main() {
	//ifstream in("D:\\input.txt");
	istream &in=cin;
	int n, m;
	int tmp;
	int i1, i2;
	long long res = 0;
	unordered_map<int, int> p2god;
	in >> n >> m;
	for (int i = 1; i <= n; ++i) {
		in >> tmp;
		p2god[i] = tmp;
	}
	for (int i = 0; i < m; ++i) {
		in >> i1 >> i2;
		int rmi = p2god[i1] > p2god[i2] ? i1 : i2;
		p2god[rmi] = 0;
	}
	for (unordered_map<int, int>::iterator it = p2god.begin(); it != p2god.end(); ++it) {
		res += it->second;
	}

	cout << res << endl;
	//cin >> res;

	return 0;
}


#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <functional>
#include <algorithm>
#include <ctime>
#include <cmath>
#include <vector>
#include <unordered_map>
#include <unordered_set>
using namespace std;

int main() {
	//ifstream in("D:\\input.txt");
	istream &in=cin;
	int n, m;
	int tmp;
	int i1, i2;
	long long res = 0;
	unordered_map<int, int> p2gold;
	unordered_map<int, int> p2g;
	in >> n >> m;
	vector<bool> g(n + 1,false);
	for (int i = 1; i <= n; ++i) {
		in >> tmp;
		p2gold[i] = tmp;
		p2g[i] = i;
		g[i] = true;
	}

	for (int i = 0; i < m; ++i) {
		in >> i1 >> i2;
		while (p2g[i1] != i1)
			i1 = p2g[i1];
		while (p2g[i2] != i2)
			i2 = p2g[i2];
		if (p2g[i1] == p2g[i2])
			continue;
		if (p2gold[p2g[i1]] < p2gold[p2g[i2]]) {
			g[p2g[i2]] = false;
			p2g[i2] = p2g[i1];
		}
		else {
			g[p2g[i1]] = false;
			p2g[i1] = p2g[i2];
		}
	}
	for (int i = 1; i <= n;++i) {
		if (g[i])
			res += p2gold[i];
	}
	cout << res << endl;
	//cin >> res;

	return 0;
}


#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <functional>
#include <algorithm>
#include <ctime>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <sstream>
#include <unordered_set>
#include <unordered_map>
#include <sstream>
#include <set>
#include <cassert>
using namespace std;

//ifstream in("C:\\input.txt");
istream& in = cin;

typedef long long LL;
#define pii pair<int,int>
#define pll pair<LL,LL>
#define mp make_pair
#define pb push_back

int n, m;
int val[100010];
vector<int> vi[100010];

void input(){
	in >> n >> m;
	for (int i = 1; i <= n; ++i)
		in >> val[i];

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

}
bool vis[100010];

/*LL dfs(int p){
	if (vis[p])
		return (1e9)+1;
	vis[p] = 1;
	int ret = val[p];
	for (int k : vi[p]){
		int r = dfs(k);
		ret = min(ret, r);
	}
	return ret;
}*/

int main(){

	int TEST_CASE = 1;
	//in >> TEST_CASE;
	while (TEST_CASE-- > 0){
		input();

		LL ans = 0;
		for (int i = 1; i <= n; ++i){
			if (vis[i])
				continue;

			queue<int> qi;
			qi.push(i);
			int tmp = val[i];
			while (!qi.empty()){
				int u = qi.front();
				qi.pop();
				for (int v : vi[u]){
					if (!vis[v]){
						vis[v] = 1;
						if (tmp > val[v]){
							tmp = val[v];
						}
						qi.push(v);
					}
				}
			}
			ans += tmp;
		}
		cout << ans << endl;

	}

	return 0;
}


#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <functional>
#include <algorithm>
#include <ctime>
#include <cmath>
#include <vector>
#include <unordered_map>
#include <unordered_set>
using namespace std;

int main() {
	//ifstream in("D:\\input.txt");
	istream &in=cin;
	int n, m;
	int tmp;
	int i1, i2;
	long long res = 0;
	unordered_map<int, int> p2gold;
	unordered_map<int, int> p2g;
	in >> n >> m;
	vector<bool> g(n + 1,false);
	for (int i = 1; i <= n; ++i) {
		in >> tmp;
		p2gold[i] = tmp;
		p2g[i] = i;
		g[i] = true;
	}
	int t2, t1;
	for (int i = 0; i < m; ++i) {
		in >> i1 >> i2;
		t1 = i1;
		t2 = i2;
		while (p2g[i1] != i1)
			i1 = p2g[i1];
		while (p2g[i2] != i2)
			i2 = p2g[i2];
		while (p2g[t1] != t1) {
			tmp = p2g[t1];
			p2g[t1] = i1;
			t1 = tmp;
		}
		while (p2g[t2] != t2) {
			tmp = p2g[t2];
			p2g[t2] = i2;
			t2 = tmp;
		}
		if (p2g[i1] == p2g[i2])
			continue;
		if (p2gold[p2g[i1]] < p2gold[p2g[i2]]) {
			g[p2g[i2]] = false;
			p2g[i2] = p2g[i1];
		}
		else {
			g[p2g[i1]] = false;
			p2g[i1] = p2g[i2];
		}
	}
	for (int i = 1; i <= n;++i) {
		if (g[i])
			res += p2gold[i];
	}
	cout << res << endl;
	//cin >> res;

	return 0;
}


#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <functional>
#include <algorithm>
#include <ctime>
#include <cmath>
#include <vector>
#include <unordered_map>
#include <unordered_set>
using namespace std;

int main() {
	//ifstream in("D:\\input.txt");
	istream &in=cin;
	int n, m;
	int tmp;
	int i1, i2;
	long long res = 0;
	unordered_map<int, int> p2gold;
	unordered_map<int, int> p2g;
	in >> n >> m;
	vector<unordered_set<int>> g(n + 1);
	for (int i = 1; i <= n; ++i) {
		in >> tmp;
		p2gold[i] = tmp;
		p2g[i] = i;
		g[i].insert(i);
	}

	for (int i = 0; i < m; ++i) {
		in >> i1 >> i2;
		if (p2gold[p2g[i1]] < p2gold[p2g[i2]]) {
			g[p2g[i2]].clear();
			p2g[i2] = p2g[i1];
		}
		else {
			g[p2g[i1]].clear();
			p2g[i1] = p2g[i2];
		}
	}
	for (int i = 1; i <= n;++i) {
		if (!g[i].empty())
			res += p2gold[i];
	}
	cout << res << endl;
	//cin >> res;

	return 0;
}


#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <functional>
#include <algorithm>
#include <ctime>
#include <cmath>
#include <vector>
#include <unordered_map>
#include <unordered_set>
using namespace std;

int main() {
	//ifstream in("D:\\input.txt");
	istream &in=cin;
	int n, m;
	int tmp;
	int i1, i2;
	long long res = 0;
	unordered_map<int, int> p2gold;
	unordered_map<int, int> p2g;
	in >> n >> m;
	vector<bool> g(n + 1,false);
	for (int i = 1; i <= n; ++i) {
		in >> tmp;
		p2gold[i] = tmp;
		p2g[i] = i;
		g[i] = true;
	}

	for (int i = 0; i < m; ++i) {
		in >> i1 >> i2;
		int t1 = i1;
		int t2 = i2;
		while (p2g[i1] != i1)
			i1 = p2g[i1];
		while (p2g[i2] != i2)
			i2 = p2g[i2];
		p2g[t1] = i1;
		p2g[t2] = i2;
		if (p2g[i1] == p2g[i2])
			continue;
		if (p2gold[p2g[i1]] < p2gold[p2g[i2]]) {
			g[p2g[i2]] = false;
			p2g[i2] = p2g[i1];
		}
		else {
			g[p2g[i1]] = false;
			p2g[i1] = p2g[i2];
		}
	}
	for (int i = 1; i <= n;++i) {
		if (g[i])
			res += p2gold[i];
	}
	cout << res << endl;
	//cin >> res;

	return 0;
}


#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <functional>
#include <algorithm>
#include <ctime>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <sstream>
#include <unordered_set>
#include <unordered_map>
#include <sstream>
#include <set>
#include <cassert>
using namespace std;

//ifstream in("C:\\input.txt");
istream& in = cin;

typedef long long LL;
#define pii pair<int,int>
#define pll pair<LL,LL>
#define mp make_pair
#define pb push_back

int n, m;
int val[100010];
vector<int> vi[100010];

void input(){
	in >> n >> m;
	for (int i = 1; i <= n; ++i)
		in >> val[i];

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

}
bool vis[100010];

/*LL dfs(int p){
	if (vis[p])
		return (1e9)+1;
	vis[p] = 1;
	int ret = val[p];
	for (int k : vi[p]){
		int r = dfs(k);
		ret = min(ret, r);
	}
	return ret;
}*/

int main(){

	int TEST_CASE = 1;
	//in >> TEST_CASE;
	while (TEST_CASE-- > 0){
		input();

		LL ans = 0;
		for (int i = 1; i <= n; ++i){
			if (vis[i])
				continue;

			queue<int> qi;
			qi.push(i);
			int tmp = val[i];
			while (!qi.empty()){
				int u = qi.front();
				qi.pop();
				for (int v : vi[u]){
					if (!vis[v]){
						vis[v] = 1;
						if (tmp > val[v]){
							tmp = val[v];
						}
						qi.push(v);
					}
				}
			}
		}
		cout << ans << endl;

	}

	return 0;
}


#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <functional>
#include <algorithm>
#include <ctime>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <sstream>
#include <unordered_set>
#include <unordered_map>
#include <sstream>
#include <set>
#include <cassert>
using namespace std;

ifstream in("C:\\input.txt");
//istream& in = cin;

typedef long long LL;
#define pii pair<int,int>
#define pll pair<LL,LL>
#define mp make_pair
#define pb push_back

int q;
pii data[100010];

LL mod = 1e9 + 7;

void input(){
	in >> q;
	for (int i = 0; i < q; ++i){
		in >> data[i].first >> data[i].second;

	}

}

LL p[1000010];

int main(){

	int TEST_CASE = 1;
	//in >> TEST_CASE;
	while (TEST_CASE-- > 0){
		input();

		p[1] = 1;
		for (int i = 2; i < 1000010; ++i){
			p[i] = p[i - 1] * 2 % mod;
		}

	}

	return 0;
}


#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <functional>
#include <algorithm>
#include <ctime>
#include <cmath>
#include <vector>
#include <unordered_map>
#include <unordered_set>
using namespace std;

int main() {
	//ifstream in("D:\\input.txt");
	istream &in=cin;
	int n, m = 0;
	int tmp;
	int i1, i2;
	long long res = 0;
	unordered_map<int, int> p2gold;
	unordered_map<int, int> p2g;
	in >> n >> m;
	vector<bool> g(n + 1,false);
	for (int i = 1; i <= n; ++i) {
		in >> tmp;
		p2gold[i] = tmp;
		p2g[i] = i;
		g[i] = true;
	}
	int t2, t1;
	for (int i = 0; i < m; ++i) {
		in >> i1 >> i2;
		t1 = i1;
		t2 = i2;
		while (p2g[i1] != i1)
			i1 = p2g[i1];
		while (p2g[i2] != i2)
			i2 = p2g[i2];
		while (p2g[t1] != t1) {
			tmp = p2g[t1];
			p2g[t1] = i1;
			t1 = tmp;
		}
		while (p2g[t2] != t2) {
			tmp = p2g[t2];
			p2g[t2] = i2;
			t2 = tmp;
		}
		if (p2g[i1] == p2g[i2])
			continue;
		if (p2gold[p2g[i1]] < p2gold[p2g[i2]]) {
			g[p2g[i2]] = false;
			p2g[i2] = p2g[i1];
		}
		else {
			g[p2g[i1]] = false;
			p2g[i1] = p2g[i2];
		}
	}
	for (int i = 1; i <= n;++i) {
		if (g[i])
			res += p2gold[i];
	}
	cout << res << endl;
	//cin >> res;

	return 0;
}


#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <functional>
#include <algorithm>
#include <ctime>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <sstream>
#include <unordered_set>
#include <unordered_map>
#include <sstream>
#include <set>
#include <cassert>
using namespace std;

//ifstream in("C:\\input.txt");
istream& in = cin;

typedef long long LL;
#define pii pair<int,int>
#define pll pair<LL,LL>
#define mp make_pair
#define pb push_back

int n, m;
LL val[100010];
vector<int> vi[100010];

void input(){
	in >> n >> m;
	for (int i = 1; i <= n; ++i)
		in >> val[i];

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

}
bool vis[100010];

LL dfs(int p){
	if (vis[p])
		return (1e9)+1;
	vis[p] = 1;
	int ret = val[p];
	for (int k : vi[p]){
		int r = dfs(k);
		ret = min(ret, r);
	}
	return ret;
}

int main(){

	int TEST_CASE = 1;
	//in >> TEST_CASE;
	while (TEST_CASE-- > 0){
		input();

		LL ans = 0;
		for (int i = 1; i <= n; ++i){
			if (vis[i])
				continue;

			ans += dfs(i);

		}

		cout << ans << endl;

	}

	return 0;
}


#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <functional>
#include <algorithm>
#include <ctime>
#include <cmath>
#include <vector>
#include <unordered_map>
#include <unordered_set>
using namespace std;

int main() {
	//ifstream in("D:\\input.txt");
	istream &in=cin;
	int n, m;
	int tmp;
	int i1, i2;
	long long res = 0;
	unordered_map<int, int> p2gold;
	unordered_map<int, int> p2g;
	in >> n >> m;
	vector<unordered_set<int>> g(n + 1);
	for (int i = 1; i <= n; ++i) {
		in >> tmp;
		p2gold[i] = tmp;
		p2g[i] = i;
		g[i].insert(i);
	}

	for (int i = 0; i < m; ++i) {
		in >> i1 >> i2;
		if (p2g[i1] == p2g[i2])
			continue;
		if (p2gold[p2g[i1]] < p2gold[p2g[i2]]) {
			g[p2g[i2]].clear();
			p2g[i2] = p2g[i1];
		}
		else {
			g[p2g[i1]].clear();
			p2g[i1] = p2g[i2];
		}
	}
	for (int i = 1; i <= n;++i) {
		if (!g[i].empty())
			res += p2gold[i];
	}
	cout << res << endl;
	//cin >> res;

	return 0;
}


#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <functional>
#include <algorithm>
#include <ctime>
#include <cmath>
#include <vector>
#include <unordered_map>
#include <unordered_set>
using namespace std;

int main() {
	//ifstream in("D:\\input.txt");
	istream &in=cin;
	int n, m;
	int tmp;
	int i1, i2;
	long long res = 0;
	unordered_map<int, int> p2gold;
	unordered_map<int, int> p2g;
	in >> n >> m;
	vector<unordered_set<int>> g(n + 1);
	for (int i = 1; i <= n; ++i) {
		in >> tmp;
		p2gold[i] = tmp;
		p2g[i] = i;
		g[i].insert(i);
	}

	for (int i = 0; i < m; ++i) {
		in >> i1 >> i2;
		if (p2gold[p2g[i1]] < p2gold[p2g[i2]]) {
			g[p2g[i1]].insert(g[p2g[i2]].begin(), g[p2g[i2]].end());
			g[p2g[i2]].clear();
			p2g[i2] = p2g[i1];
		}
		else {
			g[p2g[i2]].insert(g[p2g[i1]].begin(), g[p2g[i1]].end());
			g[p2g[i1]].clear();
			p2g[i1] = p2g[i2];
		}
	}
	for (int i = 1; i <= n;++i) {
		if (!g[i].empty())
			res += p2gold[i];
	}
	cout << res << endl;
	//cin >> res;

	return 0;
}


#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <functional>
#include <algorithm>
#include <ctime>
#include <cmath>
#include <vector>
#include <unordered_map>
#include <unordered_set>
using namespace std;

int main() {
	//ifstream in("D:\\input.txt");
	istream &in=cin;
	int n, m;
	int tmp;
	int i1, i2;
	long long res = 0;
	unordered_map<int, int> p2gold;
	unordered_map<int, int> p2g;
	in >> n >> m;
	vector<unordered_set<int>> g(n + 1);
	for (int i = 1; i <= n; ++i) {
		in >> tmp;
		p2gold[i] = tmp;
		p2g[i] = i;
		g[i].insert(i);
	}

	for (int i = 0; i < m; ++i) {
		in >> i1 >> i2;
		if (p2gold[p2g[i1]] == p2gold[p2g[i2]])
			continue;
		if (p2gold[p2g[i1]] < p2gold[p2g[i2]]) {
			g[p2g[i2]].clear();
			p2g[i2] = p2g[i1];
		}
		else {
			g[p2g[i1]].clear();
			p2g[i1] = p2g[i2];
		}
	}
	for (int i = 1; i <= n;++i) {
		if (!g[i].empty())
			res += p2gold[i];
	}
	cout << res << endl;
	//cin >> res;

	return 0;
}


#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <functional>
#include <algorithm>
#include <ctime>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <sstream>
#include <unordered_set>
#include <unordered_map>
#include <sstream>
#include <set>
#include <cassert>
using namespace std;

//ifstream in("C:\\input.txt");
istream& in = cin;

typedef long long LL;
#define pii pair<int,int>
#define pll pair<LL,LL>
#define mp make_pair
#define pb push_back

int n, m;
int val[100010];
vector<int> vi[100010];

void input(){
	in >> n >> m;
	for (int i = 1; i <= n; ++i)
		in >> val[i];

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

}
bool vis[100010];

LL dfs(int p){
	if (vis[p])
		return (1e9)+1;
	vis[p] = 1;
	int ret = val[p];
	for (int k : vi[p]){
		int r = dfs(k);
		ret = min(ret, r);
	}
	return ret;
}

int main(){

	int TEST_CASE = 1;
	//in >> TEST_CASE;
	while (TEST_CASE-- > 0){
		input();

		LL ans = 0;
		for (int i = 1; i <= n; ++i){
			if (vis[i])
				continue;

			ans += dfs(i);

		}

		cout << ans << endl;

	}

	return 0;
}


#include<bits/stdc++.h>

using namespace std;
const int maxN = 1e5+1;
int n,m;
int cost[maxN],mark[maxN];
vector<vector<int> > v;
long long res;

void DFS(int i) {
    if(mark[i])
        return;
    for(auto it: v[i]) {
        if(cost[it]<cost[i]) {
            cost[i]=cost[it];
        }
        cost[it]=0;
        DFS(it);
    }
    mark[i]=1;
}

void solv() {
    cin>>n>>m;
    v.resize(n+1,vector<int> ());
    for(int i=1; i<=n; ++i) {
        cin>>cost[i];
    }
    for(int i=1; i<=m; ++i) {
        int a,b;
        cin>>a>>b;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    for(int i=1; i<=n; ++i) {
        DFS(i);
    }
    for(int i=1; i<=n; ++i) {
        res+=cost[i];
    }
    cout<<res;
}

int mdfs(int u){
    mark[u] = 1;
    int ret = cost[u];
    for(auto iv: v[u]){
        if(!mark[iv])
            ret = min(ret, mdfs(iv));
    }
    return ret;
}

long long solve2(){
    cin>>n>>m;
    v.resize(n+1,vector<int> ());
    for(int i=1; i<=n; ++i) {
        cin>>cost[i];
    }
    for(int i=1; i<=m; ++i) {
        int a,b;
        cin>>a>>b;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    long long res = 0;
    memset(mark, 0, sizeof mark);
    for(int i = 1; i <= n; ++i)
        if(!mark[i]){
            int t = mdfs(i);
            res += t;
//            cout << i << " " << t << '\n';
        }
    return res;
}

int main() {
//    freopen("CF.inp","r",stdin);
//    freopen("CF.out","w",stdout);
    cout << solve2() << '\n';
    return 0;
}


#include<bits/stdc++.h>

using namespace std;
const int maxN = 1e5+1;
int n,m;
int cost[maxN],mark[maxN];
vector<vector<int> > v;
long long res;

void DFS(int i) {
    if(mark[i])
        return;
    for(auto it: v[i]) {
        if(cost[it]<cost[i]) {
            cost[i]=cost[it];
        }
        cost[it]=0;
        DFS(it);
    }
    mark[i]=1;
}

void solv() {
    cin>>n>>m;
    v.resize(n+1,vector<int> ());
    for(int i=1; i<=n; ++i) {
        cin>>cost[i];
    }
    for(int i=1; i<=m; ++i) {
        int a,b;
        cin>>a>>b;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    for(int i=1; i<=n; ++i) {
        DFS(i);
    }
    for(int i=1; i<=n; ++i) {
        res+=cost[i];
    }
    cout<<res;
}

int mdfs(int u){
    mark[u] = 1;
    int ret = cost[u];
    for(auto iv: v[u]){
        if(!mark[iv])
            ret = min(ret, mdfs(iv));
    }
    return ret;
}

int solve2(){
    cin>>n>>m;
    v.resize(n+1,vector<int> ());
    for(int i=1; i<=n; ++i) {
        cin>>cost[i];
    }
    for(int i=1; i<=m; ++i) {
        int a,b;
        cin>>a>>b;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    int res = 0;
    memset(mark, 0, sizeof mark);
    for(int i = 1; i <= n; ++i)
        if(!mark[i]){
            int t = mdfs(i);
            res += t;
            cout << i << " " << t << '\n';
        }
    return res;
}

int main() {
//    freopen("CF.inp","r",stdin);
//    freopen("CF.out","w",stdout);
    cout << solve2() << '\n';
    return 0;
}


#include<bits/stdc++.h>

using namespace std;
const int maxN = 1e5+1;
int n,m;
int cost[maxN],mark[maxN];
vector<vector<int> > v;
long long res;

int DFS(int u) {
    if(mark[u]) return 0;
    mark[u]=1;
    int res=cost[u];
    for(auto it : v[u]){
        if(!mark[it]){
            res=min(res,DFS(it));
        }
    }
    return res;
}

void solv() {
    cin>>n>>m;
    v.resize(n+1,vector<int> ());
    for(int i=1; i<=n; ++i) {
        cin>>cost[i];
    }
    for(int i=1; i<=m; ++i) {
        int a,b;
        cin>>a>>b;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    res=0;
    for(int i=1; i<=n; ++i) {
        res+=DFS(i);
    }
    cout<<res;
}

int main() {
    freopen("CF.inp","r",stdin);
    freopen("CF.out","w",stdout);
    solv();
    return 0;
}


#include<bits/stdc++.h>

using namespace std;
const int maxN = 1e5+1;
int n,m;
int cost[maxN],mark[maxN];
vector<vector<int> > v;
long long res;

void DFS(int i) {
    if(mark[i])
        return;
    for(auto it: v[i]) {
        if(cost[it]<cost[i]) {
            cost[i]=cost[it];
        }
        cost[it]=0;
        DFS(it);
    }
    mark[i]=1;
}

void solv() {
    cin>>n>>m;
    v.resize(n+1,vector<int> ());
    for(int i=1; i<=n; ++i) {
        cin>>cost[i];
    }
    for(int i=1; i<=m; ++i) {
        int a,b;
        cin>>a>>b;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    for(int i=1; i<=n; ++i) {
        DFS(i);
    }
    for(int i=1; i<=n; ++i) {
        res+=cost[i];
    }
    cout<<res;
}

int mdfs(int u){
    mark[u] = 1;
    int ret = cost[u];
    for(auto iv: v[u]){
        if(!mark[iv])
            ret = min(ret, mdfs(iv));
    }
    return ret;
}

int solve2(){
    cin>>n>>m;
    v.resize(n+1,vector<int> ());
    for(int i=1; i<=n; ++i) {
        cin>>cost[i];
    }
    for(int i=1; i<=m; ++i) {
        int a,b;
        cin>>a>>b;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    int res = 0;
    memset(mark, 0, sizeof mark);
    for(int i = 1; i <= n; ++i)
        if(!mark[i]){
            int t = mdfs(i);
            res += t;
//            cout << i << " " << t << '\n';
        }
    return res;
}

int main() {
//    freopen("CF.inp","r",stdin);
//    freopen("CF.out","w",stdout);
    cout << solve2() << '\n';
    return 0;
}


#include<bits/stdc++.h>

using namespace std;
const int maxN = 1e5+1;
int n,m;
int cost[maxN],mark[maxN];
long long res;

void process(int a,int b){
    if(a<b){
        cost[b]=cost[a];
        mark[b]=1;
    } else {
        cost[a]=cost[b];
        mark[a]=1;
    }
}

void solv(){
    cin>>n>>m;
    for(int i=1;i<=n;++i){
        cin>>cost[i];
    }
    for(int i=1;i<=m;++i){
        int a,b;
        cin>>a>>b;
        process(a,b);
    }
    for(int i=1;i<=n;++i){
        res+=(mark[i]==0?cost[i]:0);
    }
    cout<<res;
}

int main() {
//    freopen("CF.inp","r",stdin);
//    freopen("CF.out","w",stdout);
    solv();
    return 0;
}


#include<bits/stdc++.h>

using namespace std;
const int maxN = 1e5+1;
int n,m;
int cost[maxN],mark[maxN];
vector<vector<int> > v;
long long res;

void DFS(int i) {
    if(mark[i])
        return;
    for(auto it: v[i]) {
        if(cost[it]<cost[i]) {
            cost[i]=cost[it];
        }
        cost[it]=0;
    }
    mark[i]=1;
}

void solv() {
    cin>>n>>m;
    v.resize(n+1,vector<int> ());
    for(int i=1; i<=n; ++i) {
        cin>>cost[i];
    }
    for(int i=1; i<=m; ++i) {
        int a,b;
        cin>>a>>b;
        v[a].push_back(b);
    }
    for(int i=1; i<=n; ++i) {
        DFS(i);
    }
    for(int i=1; i<=n; ++i) {
        res+=cost[i];
    }
    cout<<res;
}

int main() {
//    freopen("CF.inp","r",stdin);
//    freopen("CF.out","w",stdout);
    solv();
    return 0;
}


#include<bits/stdc++.h>

using namespace std;
const int maxN = 1e5+1;
int n,m;
int cost[maxN],mark[maxN];
vector<vector<int> > v;
long long res;

void DFS(int i) {
    if(mark[i])
        return;
    for(auto it: v[i]) {
        if(cost[it]<cost[i]) {
            cost[i]=cost[it];
        }
        cost[it]=0;
        DFS(it);
    }
    mark[i]=1;
}

void solv() {
    cin>>n>>m;
    v.resize(n+1,vector<int> ());
    for(int i=1; i<=n; ++i) {
        cin>>cost[i];
    }
    for(int i=1; i<=m; ++i) {
        int a,b;
        cin>>a>>b;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    for(int i=1; i<=n; ++i) {
        DFS(i);
    }
    for(int i=1; i<=n; ++i) {
        res+=cost[i];
    }
    cout<<res;
}

int mdfs(int u){
    mark[u] = 1;
    int ret = cost[u];
    for(auto iv: v[u]){
        if(!mark[iv])
            ret = min(ret, mdfs(iv));
    }
    return ret;
}

int solve2(){
    cin>>n>>m;
    v.resize(n+1,vector<int> ());
    for(int i=1; i<=n; ++i) {
        cin>>cost[i];
    }
    for(int i=1; i<=m; ++i) {
        int a,b;
        cin>>a>>b;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    int res = 0;
    memset(mark, 0, sizeof mark);
    for(int i = 1; i <= n; ++i)
        if(!mark[i]){
            int t = mdfs(i);
            res += t;
//            cout << i << " " << t << '\n';
        }
    return res;
}

int main() {
    freopen("CF.inp","r",stdin);
    freopen("CF.out","w",stdout);
    cout << solve2() << '\n';
    return 0;
}


#include<bits/stdc++.h>

using namespace std;
const int maxN = 1e5+1;
int n,m;
int cost[maxN],mark[maxN];
vector<vector<int> > v;
long long res;

int DFS(int u) {
    if(mark[u]) return 0;
    mark[u]=1;
    int res=cost[u];
    for(auto it : v[u]){
        if(!mark[it]){
            res=min(res,DFS(it));
        }
    }
    return res;
}

void solv() {
    cin>>n>>m;
    v.resize(n+1,vector<int> ());
    for(int i=1; i<=n; ++i) {
        cin>>cost[i];
    }
    for(int i=1; i<=m; ++i) {
        int a,b;
        cin>>a>>b;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    res=0;
    for(int i=1; i<=n; ++i) {
        res+=DFS(i);
    }
    cout<<res;
}

int main() {
//    freopen("CF.inp","r",stdin);
//    freopen("CF.out","w",stdout);
    solv();
    return 0;
}


#include<bits/stdc++.h>

using namespace std;
const int maxN = 1e5+1;
int n,m;
int cost[maxN],mark[maxN];
vector<vector<int> > v;
long long res;

void DFS(int i) {
    if(mark[i])
        return;
    for(auto it: v[i]) {
        if(cost[it]<cost[i]) {
            cost[i]=cost[it];
        }
        cost[it]=0;
        DFS(it);
    }
    mark[i]=1;
}

void solv() {
    cin>>n>>m;
    v.resize(n+1,vector<int> ());
    for(int i=1; i<=n; ++i) {
        cin>>cost[i];
    }
    for(int i=1; i<=m; ++i) {
        int a,b;
        cin>>a>>b;
        v[a].push_back(b);
    }
    for(int i=1; i<=n; ++i) {
        DFS(i);
    }
    for(int i=1; i<=n; ++i) {
        res+=cost[i];
    }
    cout<<res;
}

int main() {
//    freopen("CF.inp","r",stdin);
//    freopen("CF.out","w",stdout);
    solv();
    return 0;
}


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

#define ll long long int

ll bfs(ll start, vector<bool> &vis, vector<ll> gold, vector<vector<ll>> graph){
    ll res = gold[start];

    vis[start] = true;

    queue<ll> q;
    q.push(start);

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

        for(int i = 0; i < graph[t].size(); i ++){
            int node = graph[t][i];
            res = min(res, gold[node]);

            if(!vis[node]) {
                vis[node] = true;
                q.push(node);
            }
        }
    }

    return res;
}

ll solve(vector<ll> gold, vector<vector<ll>> graph){
    ll n = graph.size(), res = 0;

    vector<bool> vis(n, false);

    for(int i = 0; i < n; i ++){
        if(!vis[i]) {
            res += (graph[i].size() == 0) ? gold[i] : bfs(i, vis, gold, graph);
        }
    }

    return res;
}

int main() {
	ll n, m, u, v;

	cin>>n>>m;

	vector<ll> gold(n);
	vector<vector<ll>> graph(n);

	for(ll i = 0; i < n; i ++) cin>>gold[i];

	for(ll i = 0; i < m; i ++){
	    cin>>u>>v;
	    graph[u - 1].push_back(v - 1);
	    graph[v - 1].push_back(u - 1);
	}

	cout<<solve(gold, graph)<<endl;

	return 0;
}


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

#define ll long long int

int bfs(ll start, vector<bool> &vis, vector<ll> gold, vector<vector<int>> graph){
    int res = gold[start];

    queue<int> q;
    q.push(start);

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

        for(int i = 0; i < graph[t].size(); i ++){
            int node = graph[t][i];

            if(!vis[node]) {
                vis[node] = true;
                q.push(node);
                if(res > gold[node]) res = gold[node];
            }
        }
    }

    return res;
}

ll solve(vector<ll> gold, vector<vector<int>> graph){
    int n = graph.size(), res = 0;

    vector<bool> vis(n + 1, false);

    for(int i = 0; i < n; i ++){
        if(!vis[i]) {
            vis[i] = true;
            res += (graph[i].size() == 0) ? gold[i] : bfs(i, vis, gold, graph);
        }
    }

    return res;
}

int main() {
	int n, m, u, v;

	cin>>n>>m;

	vector<ll> gold(n);
	vector<vector<int>> graph(n);

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

	for(int i = 0; i < m; i ++){
	    cin>>u>>v;
	    graph[u - 1].push_back(v - 1);
	    graph[v - 1].push_back(u - 1);
	}

	cout<<solve(gold, graph)<<endl;

	return 0;
}


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

#define ll long long int

ll bfs(ll start, vector<bool> &vis, vector<ll> gold, vector<vector<ll>> graph){
    ll res = gold[start];

    vis[start] = true;

    queue<ll> q;
    q.push(start);

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

        for(ll i = 0; i < graph[t].size(); i ++){
            ll node = graph[t][i];

            if(!vis[node]) {
                vis[node] = true;
                q.push(node);
                if(res > gold[node]) res = gold[node];
            }
        }
    }

    return res;
}

ll solve(vector<ll> gold, vector<vector<ll>> graph){
    ll n = graph.size(), res = 0;

    vector<bool> vis(n, false);

    for(int i = 0; i < n; i ++){
        if(!vis[i]) {
            res += (graph[i].size() == 0) ? gold[i] : bfs(i, vis, gold, graph);
        }
    }

    return res;
}

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

	ll n, m, u, v;

	cin>>n>>m;

	vector<ll> gold(n);
	vector<vector<ll>> graph(n);

	for(ll i = 0; i < n; i ++) cin>>gold[i];

	for(ll i = 0; i < m; i ++){
	    cin>>u>>v;
	    graph[u - 1].push_back(v - 1);
	    graph[v - 1].push_back(u - 1);
	}

	cout<<solve(gold, graph)<<endl;

	return 0;
}


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

#define ll long long
#define mp make_pair
#define pb push_back

int main() {
	ios :: sync_with_stdio(0);
	int n, m;
	cin >> n >> m;
	vector <int> c(n);
	for (int i = 0; i < n; ++ i)
		cin >> c[i];
	vector <vector <int> > g(n);
	for (int i = 0; i < m; ++ i) {
		int u, v;
		cin >> u >> v;
		-- u; -- v;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	vector <int> vis(n);
	ll ans = 0;
	for (int i = 0; i < n; ++ i) if (!vis[i]) {
		int mn = 1e9;
		vis[i] = 1;
		vector <int> que; que.push_back(i);
		for (int ql = 0; ql < que.size(); ++ ql) {
			int u = que[ql];
			mn = min(mn, c[u]);
			for (int j = 0; j < g[u].size(); ++ j) {
				if (!vis[g[u][j]]) vis[g[u][j]] = 1, que.push_back(g[u][j]);
			}
		}
		ans += mn;
	}
	cout << ans << endl;
	return 0;
}


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

#define ll long long int

ll bfs(ll start, vector<bool> &vis, vector<ll> gold, vector<vector<ll>> graph){
    ll res = gold[start];

    vis[start] = true;

    queue<ll> q;
    q.push(start);

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

        for(int i = 0; i < graph[t].size(); i ++){
            int node = graph[t][i];

            if(res == 0) return 0;

            if(!vis[node]) {
                vis[node] = true;
                q.push(node);
                res = min(res, gold[node]);
            }
        }
    }

    return res;
}

ll solve(vector<ll> gold, vector<vector<ll>> graph){
    ll n = graph.size(), res = 0;

    vector<bool> vis(n, false);

    for(int i = 0; i < n; i ++){
        if(!vis[i]) {
            res += (graph[i].size() == 0) ? gold[i] : bfs(i, vis, gold, graph);
        }
    }

    return res;
}

int main() {
	ll n, m, u, v;

	cin>>n>>m;

	vector<ll> gold(n);
	vector<vector<ll>> graph(n);

	for(ll i = 0; i < n; i ++) cin>>gold[i];

	for(ll i = 0; i < m; i ++){
	    cin>>u>>v;
	    graph[u - 1].push_back(v - 1);
	    graph[v - 1].push_back(u - 1);
	}

	cout<<solve(gold, graph)<<endl;

	return 0;
}


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

#define ll long long int

void dfs(ll start, vector<bool> &vis, vector<ll> gold, vector<vector<ll>> graph, ll &res){
    vis[start] = true;
    res = min(gold[start], res);

    for(int i = 0; i < graph[start].size(); i ++){
        if(!vis[graph[start][i]]){
            dfs(graph[start][i], vis, gold, graph, res);
        }
    }
}

ll solve(vector<ll> gold, vector<vector<ll>> graph){
    ll n = graph.size(), res = 0;

    vector<bool> vis(n, false);

    for(int i = 0; i < n; i ++){
        if(!vis[i]) {
            ll ans = 1000000001;
            dfs(i, vis, gold, graph, ans);
            res += ans;
        }
    }

    return res;
}

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

	ll n, m, u, v;

	cin>>n>>m;

	vector<ll> gold(n);
	vector<vector<ll>> graph(n);

	for(ll i = 0; i < n; i ++) cin>>gold[i];

	for(ll i = 0; i < m; i ++){
	    cin>>u>>v;
	    graph[u - 1].push_back(v - 1);
	    graph[v - 1].push_back(u - 1);
	}

	cout<<solve(gold, graph)<<endl;

	return 0;
}


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

#define ll long long int

ll bfs(ll start, vector<bool> &vis, vector<ll> gold, vector<vector<ll>> graph){
    ll res = gold[start];

    queue<ll> q;
    q.push(start);

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

        for(ll i = 0; i < graph[t].size(); i ++){
            ll node = graph[t][i];

            if(!vis[node]) {
                vis[node] = true;
                q.push(node);
                if(res > gold[node]) res = gold[node];
            }
        }
    }

    return res;
}

ll solve(vector<ll> gold, vector<vector<ll>> graph){
    ll n = graph.size(), res = 0;

    vector<bool> vis(n, false);

    for(int i = 0; i < n; i ++){
        if(!vis[i]) {
            vis[i] = true;
            res += (graph[i].size() == 0) ? gold[i] : bfs(i, vis, gold, graph);
        }
    }

    return res;
}

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

	ll n, m, u, v;

	cin>>n>>m;

	vector<ll> gold(n);
	vector<vector<ll>> graph(n);

	for(ll i = 0; i < n; i ++) cin>>gold[i];

	for(ll i = 0; i < m; i ++){
	    cin>>u>>v;
	    graph[u - 1].push_back(v - 1);
	    graph[v - 1].push_back(u - 1);
	}

	cout<<solve(gold, graph)<<endl;

	return 0;
}


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

#define ll long long int

ll bfs(ll start, vector<bool> &vis, vector<ll> gold, vector<vector<ll>> graph){
    ll res = gold[start];

    vis[start] = true;

    queue<ll> q;
    q.push(start);

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

        for(int i = 0; i < graph[t].size(); i ++){
            int node = graph[t][i];
            res = min(res, gold[node]);

            if(!vis[node]) {
                vis[node] = true;
                q.push(node);
            }
        }
    }

    return res;
}

ll solve(vector<ll> gold, vector<vector<ll>> graph){
    ll n = graph.size(), res = 0;

    vector<bool> vis(n, false);

    for(int i = 0; i < n; i ++){
        if(!vis[i]) {
            res += bfs(i, vis, gold, graph);
        }
    }

    return res;
}

int main() {
	ll n, m, u, v;

	cin>>n>>m;

	vector<ll> gold(n);
	vector<vector<ll>> graph(n);

	for(ll i = 0; i < n; i ++) cin>>gold[i];

	for(ll i = 0; i < m; i ++){
	    cin>>u>>v;
	    graph[u - 1].push_back(v - 1);
	    graph[v - 1].push_back(u - 1);
	}

	cout<<solve(gold, graph)<<endl;

	return 0;
}


/*
Author : Bute_Forces || sarthak0797
*/

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

#define ll long long int
#define pii pair < int , pair < int , int > >
#define pi pair < int , int >
#define pp pair < ll , ll >
#define mod 1000000007
#define pb push_back
#define mp make_pair

ll cost[100004] = {0};
vector <vector<ll>> adj(100004);
bool visited[100004] = {0};
ll mi = LLONG_MAX;
void dfs(ll u)
{
    visited[u] = 1;
    if(cost[u] < mi && cost[u] >= 0)
    {
        mi = cost[u];
        cost[u] = -1;
    }
    else
    {
        cost[u] = -1;
    }
    for(auto i = adj[u].begin(); i != adj[u].end(); i++)
    {
        if(!visited[*i])
        {
            dfs(*i);
        }
    }
}
int main()
{
    cin.sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n,p;
	cin >> n >> p;
	adj.clear();
	for(int i = 1; i <= n; i++)
	{
	    cin >> cost[i];
	}
	for(int i = 0; i < p; i++)
	{
	    int x,y;
	    cin >> x >> y;
	    adj[x].pb(y);
	    adj[y].pb(x);
	}
	ll sum = 0;
	for(int i = 1; i <= n; i++)
	{
	    mi = LLONG_MAX;
	    if(!visited[i]){
	        dfs(i);
	        if(mi > 0) sum += mi;
	    }
	}
	cout << sum;
}


/*
Author : Bute_Forces || sarthak0797
*/

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

#define ll long long int
#define pii pair < int , pair < int , int > >
#define pi pair < int , int >
#define pp pair < ll , ll >
#define mod 1000000007
#define pb push_back
#define mp make_pair

ll cost[100004] = {0};
vector <vector<ll>> adj(100004);
bool visited[100004] = {0};
ll mi = LLONG_MAX;
void dfs(ll u)
{
    visited[u] = 1;
    if(cost[u] < mi && cost[u] > 0)
    {
        mi = cost[u];
        cost[u] = -1;
    }
    else
    {
        cost[u] = -1;
    }
    for(auto i = adj[u].begin(); i != adj[u].end(); i++)
    {
        if(!visited[*i])
        {
            dfs(*i);
        }
    }
}
int main()
{
    cin.sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n,p;
	cin >> n >> p;
	adj.clear();
	for(int i = 1; i <= n; i++)
	{
	    cin >> cost[i];
	}
	for(int i = 0; i < p; i++)
	{
	    int x,y;
	    cin >> x >> y;
	    adj[x].pb(y);
	    adj[y].pb(x);
	}
	ll sum = 0;
	for(int i = 1; i <= n; i++)
	{
	    mi = LLONG_MAX;
	    if(!visited[i]){
	        dfs(i);
	        if(mi > 0) sum += mi;
	    }
	}
	cout << sum;
}


/*
Author : Bute_Forces || sarthak0797
*/

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

#define ll long long int
#define pii pair < int , pair < int , int > >
#define pi pair < int , int >
#define pp pair < ll , ll >
#define mod 1000000007
#define pb push_back
#define mp make_pair

ll cost[100004] = {0};
vector <vector<int>> adj(100004);
bool visited[100004] = {0};
ll mi = LLONG_MAX;
void dfs(int u)
{
    visited[u] = 1;
    if(cost[u] < mi && cost[u] != -1)
    {
        mi = cost[u];
        cost[u] = -1;
    }
    else
    {
        cost[u] = -1;
    }
    for(auto i = adj[u].begin(); i != adj[u].end(); i++)
    {
        if(!visited[*i])
        {
            dfs(*i);
        }
    }
}
int main()
{
    cin.sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n,p;
	cin >> n >> p;
	for(int i = 1; i <= n; i++)
	{
	    cin >> cost[i];
	}
	for(int i = 0; i < p; i++)
	{
	    int x,y;
	    cin >> x >> y;
	    adj[x].pb(y);
	}
	int sum = 0;
	for(int i = 1; i <= n; i++)
	{
	    mi = LLONG_MAX;
	    if(!visited[i]){
	        dfs(i);
	        sum += mi;
	    }
	}
	cout << sum << "\n";
}


/*
Author : Bute_Forces || sarthak0797
*/

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

#define ll long long int
#define pii pair < int , pair < int , int > >
#define pi pair < int , int >
#define pp pair < ll , ll >
#define mod 1000000007
#define pb push_back
#define mp make_pair

ll cost[100004];
vector <vector<int>> adj(100004);
bool visited[100004] = {0};
ll mi = LLONG_MAX;
void dfs(int u)
{
    visited[u] = 1;
    if(cost[u] < mi)
    {
        mi = cost[u];
    }
    else
    {
        cost[u] = -1;
    }
    for(auto i = adj[u].begin(); i != adj[u].end(); i++)
    {
        if(!visited[*i])
        {
            dfs(*i);
        }
    }
}
int main()
{
    cin.sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n,p;
	cin >> n >> p;
	for(int i = 1; i <= n; i++)
	{
	    cin >> cost[i];
	}
	for(int i = 0; i < p; i++)
	{
	    int x,y;
	    cin >> x >> y;
	    adj[x].pb(y);
	}
	for(int i = 1; i <= n; i++)
	{
	    mi = LLONG_MAX;
	    if(!visited[i]) dfs(i);
	}
	int sum = 0;
	for(int i = 1; i <= n; i++)
	{
	    if(cost[i] != -1) sum += cost[i];
	}
	cout << sum;
}


#include<iostream>
#include<map>
using namespace std;
#define ll long long

struct node
{
    int x,y;
    node(int x=0,int y=0):x(x),y(y){};
    bool operator < (const node n1) const
    {
        return !(x==n1.x&&y==n1.y);
    }
};

map <node , int > v;

ll gcd(ll a,ll b)
{
    if(b==0) return -2;
    if(a==0) return -1;
    ll t;
    while(b)
    {
        t=a;
        a=b;
        b=t%b;
    }
    if(a<=0) return -a;
    return a;
}

int n,a[200005],b[200005];

int main()
{
    int zer=0;
    cin>>n;
    for(int i=0;i<n;i++) cin>>a[i];
    for(int i=0;i<n;i++) cin>>b[i];
    for(int i=0;i<n;i++)
    {
        int s=gcd(a[i],b[i]);
        if(s==-1) continue;
        if(s==-2)
        {
            zer++;
            continue;
        }
        if(a[i]<0) s=-s;
        //cout<<s<<endl;;
        v[node(a[i]/s,b[i]/s)]++;
    }
    map<node,int>::iterator it = v.begin();
    int ans=0;
    for(;it!=v.end();it++)
    {
        if(it->second>ans) ans=it->second;
    }
    cout<<ans+zer<<endl;
}


#include<iostream>
#include<math.h>
#include<stdlib.h>
using namespace std;
const long long mod=1e6+7;
int a[mod+1];
int xx[200005];
int yy[200005];
int qwer=0;
long long Hash(long long x,long long y)
{
    return (x*x*1637%mod+y*y* 1657%mod+abs(x+y)*1663)%mod;
}
bool fn(long long &x,long long &y)
{
    int a,b;
    if(y==0&&x==0)
    {
        qwer++;
        return false;
    }
    if(y==0)
    {
        ::a[0]++;
        return false;
    }
    if(x==0)
    {
        return false;
    }
    a=max(x,y);
    b=min(x,y);
    while(b!=0)
    {
        int t=a;
        a=b;
        b=t%b;
    }
    x/=a;
    y/=a;
    return true;
}
int main()
{
    int n;
    long long x,y;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>xx[i];
    }
    for(int i=0;i<n;i++)
    {
        cin>>yy[i];
    }
    for(int i=0;i<n;i++)
    {
        x=xx[i];
        y=yy[i];
        if(fn(x,y)==false) continue;
    //    cout<<x<<' '<<y<<endl;
        a[Hash(x,y)]++;
    }
    int ma=0;
    for(int i=0;i<mod;i++)
    {
        if(a[i]>ma) ma=a[i];
    }
    cout<<ma+qwer;
}


#include<iostream>
#include<math.h>
using namespace std;
const long long mod=1e6+7;
int a[mod+1];
int xx[200005];
int yy[200005];
int qwer=0;
long long Hash(long long x,long long y)
{
    return (x*x*17%mod+y*y*13%mod+x-y)%mod;
}
bool fn(long long &x,long long &y)
{
    int a,b;
    if(y==0&&x==0)
    {
        qwer++;
        return false;
    }
    if(y==0)
    {
        ::a[0]++;
        return false;
    }
    if(x==0)
    {
        return false;
    }
    a=max(x,y);
    b=min(x,y);
    while(b!=0)
    {
        int t=a;
        a=b;
        b=t%b;
    }
    x/=a;
    y/=a;
    return true;
}
int main()
{
    int n;
    long long x,y;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>xx[i];
    }
    for(int i=0;i<n;i++)
    {
        cin>>yy[i];
    }
    for(int i=0;i<n;i++)
    {
        x=xx[i];
        y=yy[i];
        if(fn(x,y)==false) continue;
    //    cout<<x<<' '<<y<<endl;
        a[Hash(x,y)]++;
    }
    int ma=0;
    for(int i=0;i<mod;i++)
    {
        if(a[i]>ma) ma=a[i];
    }
    cout<<ma+qwer;
}


#include<iostream>
#include<math.h>
using namespace std;
const long long mod=1e8+7;
int a[mod+1];
int xx[200005];
int yy[200005];

long long Hash(long long x,long long y)
{
    return (x*x%mod+y*y%mod+x-y)%mod;
}
bool fn(long long &x,long long &y)
{
    int a,b;
    if(y==0&&x==0)
    {
        for(long long i=0;i<mod;i++)
            ::a[i]++;
        return false;
    }
    if(y==0)
    {
        x=0;
        return true;
    }
    if(x==0)
    {
        return false;
    }
    a=max(x,y);
    b=min(x,y);
    while(b!=0)
    {
        int t=a;
        a=b;
        b=t%b;
    }
    x/=a;
    y/=a;
    return true;
}
int main()
{
    int n;
    long long x,y;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>xx[i];
    }
    for(int i=0;i<n;i++)
    {
        cin>>yy[i];
    }
    for(int i=0;i<n;i++)
    {
        x=xx[i];
        y=yy[i];
        if(fn(x,y)==false) continue;
    //    cout<<x<<' '<<y<<endl;
        a[Hash(x,y)]++;
    }
    int ma=0;
    for(int i=0;i<mod;i++)
    {
        if(a[i]>ma) ma=a[i];
    }
    cout<<ma;
}


#include<iostream>
#include<map>
using namespace std;
#define ll long long

struct node
{
    int x,y;
    node(int x=0,int y=0):x(x),y(y){};
    bool operator < (const node n1) const
    {
        return !(x==n1.x&&y==n1.y);
    }
};

map <node , int > v;

ll gcd(ll a,ll b)
{
    if(a==0) return -1;
    if(b==0) return a;
    ll t;
    while(b)
    {
        t=a;
        a=b;
        b=t%b;
    }
    if(a<=0) return -a;
    return a;
}

int n,a[200005],b[200005];

int main()
{
    cin>>n;
    for(int i=0;i<n;i++) cin>>a[i];
    for(int i=0;i<n;i++) cin>>b[i];
    for(int i=0;i<n;i++)
    {
        int s=gcd(a[i],b[i]);
        if(s==-1) continue;
        if(a[i]<0) s=-s;
        //cout<<s<<endl;;
        v[node(a[i]/s,b[i]/s)]++;
    }
    map<node,int>::iterator it = v.begin();
    int ans=0;
    for(;it!=v.end();it++)
    {
        if(it->second>ans) ans=it->second;
    }
    cout<<ans<<endl;
}


#include<iostream>
#include<math.h>
using namespace std;
const long long mod=1e6+7;
int a[mod+1];
int xx[200005];
int yy[200005];
int qwer=0;
long long Hash(long long x,long long y)
{
    return (x*x*17%mod+y*y*13%mod)%mod;
}
bool fn(long long &x,long long &y)
{
    int a,b;
    if(y==0&&x==0)
    {
        qwer++;
        return false;
    }
    if(y==0)
    {
        ::a[0]++;
        return false;
    }
    if(x==0)
    {
        return false;
    }
    a=max(x,y);
    b=min(x,y);
    while(b!=0)
    {
        int t=a;
        a=b;
        b=t%b;
    }
    x/=a;
    y/=a;
    return true;
}
int main()
{
    int n;
    long long x,y;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>xx[i];
    }
    for(int i=0;i<n;i++)
    {
        cin>>yy[i];
    }
    for(int i=0;i<n;i++)
    {
        x=xx[i];
        y=yy[i];
        if(fn(x,y)==false) continue;
    //    cout<<x<<' '<<y<<endl;
        a[Hash(x,y)]++;
    }
    int ma=0;
    for(int i=0;i<mod;i++)
    {
        if(a[i]>ma) ma=a[i];
    }
    cout<<ma+qwer;
}


#include<iostream>
#include<math.h>
using namespace std;
const long long mod=1e6+7;
int a[mod+1];
int xx[200005];
int yy[200005];
int qwer=0;
long long Hash(long long x,long long y)
{
    return (x*x*17%mod+y*y*13%mod+x-y)%mod;
}
bool fn(long long &x,long long &y)
{
    int a,b;
    if(y==0&&x==0)
    {
        qwer++;
        return false;
    }
    if(y==0)
    {
        x=0;
        return true;
    }
    if(x==0)
    {
        return false;
    }
    a=max(x,y);
    b=min(x,y);
    while(b!=0)
    {
        int t=a;
        a=b;
        b=t%b;
    }
    x/=a;
    y/=a;
    return true;
}
int main()
{
    int n;
    long long x,y;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>xx[i];
    }
    for(int i=0;i<n;i++)
    {
        cin>>yy[i];
    }
    for(int i=0;i<n;i++)
    {
        x=xx[i];
        y=yy[i];
        if(fn(x,y)==false) continue;
    //    cout<<x<<' '<<y<<endl;
        a[Hash(x,y)]++;
    }
    int ma=0;
    for(int i=0;i<mod;i++)
    {
        if(a[i]>ma) ma=a[i];
    }
    cout<<ma+qwer;
}


#include<iostream>
#include<math.h>
#include<stdlib.h>
using namespace std;
const long long mod=1e6+7;
int a[mod+1];
int xx[200005];
int yy[200005];
int qwer=0;
long long Hash(long long x,long long y)
{
    return (x*x*17%mod+y*y*13%mod+abs(x+y)*7)%mod;
}
bool fn(long long &x,long long &y)
{
    int a,b;
    if(y==0&&x==0)
    {
        qwer++;
        return false;
    }
    if(y==0)
    {
        ::a[0]++;
        return false;
    }
    if(x==0)
    {
        return false;
    }
    a=max(x,y);
    b=min(x,y);
    while(b!=0)
    {
        int t=a;
        a=b;
        b=t%b;
    }
    x/=a;
    y/=a;
    return true;
}
int main()
{
    int n;
    long long x,y;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>xx[i];
    }
    for(int i=0;i<n;i++)
    {
        cin>>yy[i];
    }
    for(int i=0;i<n;i++)
    {
        x=xx[i];
        y=yy[i];
        if(fn(x,y)==false) continue;
    //    cout<<x<<' '<<y<<endl;
        a[Hash(x,y)]++;
    }
    int ma=0;
    for(int i=0;i<mod;i++)
    {
        if(a[i]>ma) ma=a[i];
    }
    cout<<ma+qwer;
}


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

int zer=0;

map <pair<int ,int >, int > v;

ll gcd(ll a,ll b)
{
    if(b==0) {zer++;return 0;}
    if(a==0) return -1;
    ll t;
    while(b)
    {
        t=a;
        a=b;
        b=t%b;
    }
    return abs(a);
}

int n,a[200005],b[200005];

int main()
{
    cin>>n;
    for(int i=0;i<n;i++) cin>>a[i];
    for(int i=0;i<n;i++) cin>>b[i];
    for(int i=0;i<n;i++)
    {
        int s=gcd(a[i],b[i]);
        if(s==0) continue;
        if(s==-1) continue;
        a[i]/=s,b[i]/=s;
        if(a[i]<0)
        {
            a[i]=-a[i];
            b[i]=-b[i];
        }
      //  cout<<a[i]<<' '<<b[i]<<endl;
        v[make_pair(a[i],b[i])]++;
    }
    map<pair<int ,int >,int>::iterator it = v.begin();
    int ans=0;
    for(;it!=v.end();it++)
    {
        if(it->second>ans) ans=it->second;
    }
    cout<<ans+zer<<endl;
}


#include<iostream>
#include<math.h>
#include<stdlib.h>
using namespace std;
const long long mod=1e6+7;
int a[mod+1];
int xx[200005];
int yy[200005];
int qwer=0;
long long Hash(long long x,long long y)
{
    return (x*x%mod*3+y*y%mod*5+abs(x+y)*7)%mod;
}
bool fn(long long &x,long long &y)
{
    int a,b;
    if(y==0&&x==0)
    {
        qwer++;
        return false;
    }
    if(y==0)
    {
        ::a[0]++;
        return false;
    }
    if(x==0)
    {
        return false;
    }
    a=max(x,y);
    b=min(x,y);
    while(b!=0)
    {
        int t=a;
        a=b;
        b=t%b;
    }
    x/=a;
    y/=a;
    return true;
}
int main()
{
    int n;
    long long x,y;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>xx[i];
    }
    for(int i=0;i<n;i++)
    {
        cin>>yy[i];
    }
    for(int i=0;i<n;i++)
    {
        x=xx[i];
        y=yy[i];
        if(fn(x,y)==false) continue;
    //    cout<<x<<' '<<y<<endl;
        a[Hash(x,y)]++;
    }
    int ma=0;
    for(int i=0;i<mod;i++)
    {
        if(a[i]>ma) ma=a[i];
    }
    cout<<ma+qwer;
}


#include<iostream>
#include<math.h>
#include<stdlib.h>
using namespace std;
const long long mod=1e6+7;
int a[mod+1];
int xx[200005];
int yy[200005];
int qwer=0;
long long Hash(long long x,long long y)
{
    return (x*x%mod+y*y%mod+abs(x+y))%mod;
}
bool fn(long long &x,long long &y)
{
    int a,b;
    if(y==0&&x==0)
    {
        qwer++;
        return false;
    }
    if(y==0)
    {
        ::a[0]++;
        return false;
    }
    if(x==0)
    {
        return false;
    }
    a=max(x,y);
    b=min(x,y);
    while(b!=0)
    {
        int t=a;
        a=b;
        b=t%b;
    }
    x/=a;
    y/=a;
    return true;
}
int main()
{
    int n;
    long long x,y;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>xx[i];
    }
    for(int i=0;i<n;i++)
    {
        cin>>yy[i];
    }
    for(int i=0;i<n;i++)
    {
        x=xx[i];
        y=yy[i];
        if(fn(x,y)==false) continue;
    //    cout<<x<<' '<<y<<endl;
        a[Hash(x,y)]++;
    }
    int ma=0;
    for(int i=0;i<mod;i++)
    {
        if(a[i]>ma) ma=a[i];
    }
    cout<<ma+qwer;
}


#include<iostream>
#include<math.h>
#include<stdlib.h>
using namespace std;
const long long mod=1e6+7;
int a[mod+1];
long long xx[200005];
long long yy[200005];
int qwer=0;
long long Hash(long long x,long long y)
{
    return (x*x%mod*31+y*y%mod*51+abs(x+y)*71)%mod;
}
bool fn(long long &x,long long &y)
{
    int a,b;
    if(y==0&&x==0)
    {
        qwer++;
        return false;
    }
    if(y==0)
    {
        ::a[0]++;
        return false;
    }
    if(x==0)
    {
        return false;
    }
    a=max(x,y);
    b=min(x,y);
    while(b!=0)
    {
        int t=a;
        a=b;
        b=t%b;
    }
    x/=a;
    y/=a;
    if(x<0)
    {
         x*=-1;
         y*=-1;
    }

    return true;
}
int main()
{
    int n;
    long long x,y;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>xx[i];
    }
    for(int i=0;i<n;i++)
    {
        cin>>yy[i];
    }
    for(int i=0;i<n;i++)
    {
        x=xx[i];
        y=yy[i];
        if(fn(x,y)==false) continue;
      //  cout<<x<<' '<<y<<endl;
        a[Hash(x,y)]++;
    }
    int ma=0;
    for(int i=0;i<mod;i++)
    {
        if(a[i]>ma) ma=a[i];
    }
    cout<<ma+qwer;
}


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

int main(){

ll n;
cin>>n;
ll a[n+1],b[n+1];
for(int i=0;i<n;i++) cin>>a[i];
for(int i=0;i<n;i++) cin>>b[i];
ll ans=0,temp=0;
for(int i=0;i<n;i++) {
	if(a[i]==0&&b[i]==0) {temp++;continue;}
	ll g=__gcd(a[i],b[i]);

	a[i]=a[i]/g;
	b[i]=b[i]/g;
}
double c[n+1];
ll k=0;
for(int i=0;i<n;i++){
    if(a[i]==0) continue;
    c[k++]=double(b[i])/a[i];
}
map<double,ll> m;
map<double,ll> :: iterator it;
for(int i=0;i<k;i++){

	   /// cout<<z<<endl;
		it=m.find(c[i]);
		if(it==m.end()) m.insert(make_pair(c[i],1));
		else (it->second)++;

}

for(it=m.begin();it!=m.end();it++){
    //cout<<it->first<<" "<<it->second<<endl;
	ans=max(ans,it->second);
}
cout<<ans+temp<<endl;

}


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

int main(){

ll n,k;
cin>>n;
int a[n+1],b[n+1];
for(int i=0;i<n;i++) cin>>a[i];
for(int i=0;i<n;i++) cin>>b[i];

for(int i=0;i<n;i++) {
	ll g=__gcd(a[i],b[i]);
	a[i]=a[i]/g;
	b[i]=b[i]/g;
}

map<double,ll> m;
map<double,ll> :: iterator it;
for(int i=0;i<n;i++){
	if(a[i]==0) continue;
		double z=(double)b[i]/a[i];
		it=m.find(z);
		if(it==m.end()) m.insert(make_pair(z,1));
		else (it->second)++;

}

ll ans=0;
for(it=m.begin();it!=m.end();it++){
	ans=max(ans,it->second);
}
cout<<ans<<endl;

}


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

int main(){

ll n;
cin>>n;
ll a[n+1],b[n+1];
for(int i=0;i<n;i++) cin>>a[i];
for(int i=0;i<n;i++) cin>>b[i];

for(int i=0;i<n;i++) {
	ll g=__gcd(a[i],b[i]);
	a[i]=a[i]/g;
	b[i]=b[i]/g;
}
double c[n+1];
ll k=0;
for(int i=0;i<n;i++){
    if(a[i]==0) continue;
    c[k++]=double(b[i])/a[i];
}
map<double,ll> m;
map<double,ll> :: iterator it;
for(int i=0;i<k;i++){

	   /// cout<<z<<endl;
		it=m.find(c[i]);
		if(it==m.end()) m.insert(make_pair(c[i],1));
		else (it->second)++;

}

ll ans=0;
for(it=m.begin();it!=m.end();it++){
    //cout<<it->first<<" "<<it->second<<endl;
	ans=max(ans,it->second);
}
cout<<ans<<endl;

}


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

int main(){

ll n;
cin>>n;
ll a[n+1],b[n+1];
for(int i=0;i<n;i++) cin>>a[i];
for(int i=0;i<n;i++) cin>>b[i];
ll ans=0,temp=0;
for(int i=0;i<n;i++) {
	if(a[i]==0&&b[i]==0) {temp++,continue;}
	ll g=__gcd(a[i],b[i]);

	a[i]=a[i]/g;
	b[i]=b[i]/g;
}
double c[n+1];
ll k=0;
for(int i=0;i<n;i++){
    if(a[i]==0) continue;
    c[k++]=double(b[i])/a[i];
}
map<double,ll> m;
map<double,ll> :: iterator it;
for(int i=0;i<k;i++){

	   /// cout<<z<<endl;
		it=m.find(c[i]);
		if(it==m.end()) m.insert(make_pair(c[i],1));
		else (it->second)++;

}

for(it=m.begin();it!=m.end();it++){
    //cout<<it->first<<" "<<it->second<<endl;
	ans=max(ans,it->second);
}
cout<<ans+temp<<endl;

}


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

int main(){

ll n;
cin>>n;
ll a[n+1],b[n+1];
for(int i=0;i<n;i++) cin>>a[i];
for(int i=0;i<n;i++) cin>>b[i];
ll ans=0,temp=0;
for(int i=0;i<n;i++) {
	if(a[i]==0&&b[i]==0) {temp++;continue;}
	if(a[i]==0||b[i]==0) continue;
	ll g=__gcd(a[i],b[i]);

	a[i]=a[i]/g;
	b[i]=b[i]/g;
}
double c[n+1];
ll k=0;
for(int i=0;i<n;i++){
    if(a[i]==0) continue;
    c[k]=double(b[i])/a[i];
    k++;
}
map<double,ll> m;
map<double,ll> :: iterator it;
for(int i=0;i<k;i++){

	   /// cout<<z<<endl;
		it=m.find(c[i]);
		if(it==m.end()) m.insert(make_pair(c[i],1));
		else (it->second)++;

}

for(it=m.begin();it!=m.end();it++){
    //cout<<it->first<<" "<<it->second<<endl;
	ans=max(ans,it->second);
}
cout<<ans+temp<<endl;

}


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

int main(){

ll n;
cin>>n;
ll a[n+1],b[n+1];
for(int i=0;i<n;i++) cin>>a[i];
for(int i=0;i<n;i++) cin>>b[i];
ll ans=0,temp=0;
for(int i=0;i<n;i++) {
	if(a[i]==0&&b[i]==0) {temp++;continue;}
	ll g=__gcd(a[i],b[i]);

	a[i]=a[i]/g;
	b[i]=b[i]/g;
}
double c[n+1];
ll k=0;
for(int i=0;i<n;i++){
    if(a[i]==0) continue;
    c[k]=double(b[i])/a[i];
    k++;
}
map<double,ll> m;
map<double,ll> :: iterator it;
for(int i=0;i<k;i++){

	   /// cout<<z<<endl;
		it=m.find(c[i]);
		if(it==m.end()) m.insert(make_pair(c[i],1));
		else (it->second)++;

}

for(it=m.begin();it!=m.end();it++){
    //cout<<it->first<<" "<<it->second<<endl;
	ans=max(ans,it->second);
}
cout<<ans+temp<<endl;

}


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

int main(){

ll n;
cin>>n;
ll a[n+1],b[n+1];
for(int i=0;i<n;i++) cin>>a[i];
for(int i=0;i<n;i++) cin>>b[i];
ll ans=0,temp=0;
for(int i=0;i<n;i++) {
	if(a[i]==0&&b[i]==0) {temp++;continue;}
	if(a[i]==0||b[i]==0) continue;
	ll g=__gcd(a[i],b[i]);

	a[i]=a[i]/g;
	b[i]=b[i]/g;
}

map<pair<ll,ll>,ll> m;
map<pair<ll,ll>,ll> :: iterator it;
for(int i=0;i<n;i++){
if(a[i]==0) continue;
	   /// cout<<z<<endl;

  if(b[i]<0){
  	a[i]=a[i]*-1;
    b[i]=b[i]*-1;
  }
if(b[i]==0) a[i]=0;
	it=m.find(make_pair(a[i],b[i]));
		if(it==m.end()) m.insert(make_pair(make_pair(a[i],b[i]),1));
		else (it->second)++;

}

for(it=m.begin();it!=m.end();it++){
    //cout<<it->first<<" "<<it->second<<endl;
	ans=max(ans,it->second);
}
cout<<ans+temp<<endl;

}


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

int main(){

ll n;
cin>>n;
ll a[n+1],b[n+1];
for(int i=0;i<n;i++) cin>>a[i];
for(int i=0;i<n;i++) cin>>b[i];

for(int i=0;i<n;i++) {
	ll g=__gcd(a[i],b[i]);
	a[i]=a[i]/g;
	b[i]=b[i]/g;
}
double c[n+1];
ll k=0;
for(int i=0;i<n;i++){
    if(a[i]==0) continue;
    c[k++]=double(b[i])/a[i];
}
map<double,ll> m;
map<double,ll> :: iterator it;
for(int i=0;i<k;i++){

	   /// cout<<z<<endl;
		it=m.find(c[i]);
		if(it==m.end()) m.insert(make_pair(c[i],1));
		else (it->second)++;

}

ll ans=0;
for(it=m.begin();it!=m.end();it++){
    cout<<it->first<<" "<<it->second<<endl;
	ans=max(ans,it->second);
}
cout<<ans<<endl;

}


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

int main(){

ll n;
cin>>n;
ll a[n+1],b[n+1];
for(int i=0;i<n;i++) cin>>a[i];
for(int i=0;i<n;i++) cin>>b[i];
ll ans=0,temp=0;
for(int i=0;i<n;i++) {
	if(a[i]==0&&b[i]==0) {temp++;continue;}
	if(a[i]==0||b[i]==0) continue;
	ll g=__gcd(a[i],b[i]);

	a[i]=a[i]/g;
	b[i]=b[i]/g;
}

map<pair<ll,ll>,ll> m;
map<pair<ll,ll>,ll> :: iterator it;
for(int i=0;i<n;i++){
if(a[i]==0) continue;
	   /// cout<<z<<endl;

  if(b[i]<0){
  	a[i]=a[i]*-1;
    b[i]=b[i]*-1;
  }
if(b[i]==0) a[i]==0;
	it=m.find(make_pair(a[i],b[i]));
		if(it==m.end()) m.insert(make_pair(make_pair(a[i],b[i]),1));
		else (it->second)++;

}

for(it=m.begin();it!=m.end();it++){
    //cout<<it->first<<" "<<it->second<<endl;
	ans=max(ans,it->second);
}
cout<<ans+temp<<endl;

}


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

int main(){

ll n;
cin>>n;
ll a[n+1],b[n+1];
for(int i=0;i<n;i++) cin>>a[i];
for(int i=0;i<n;i++) cin>>b[i];
ll ans=0,temp=0;
for(int i=0;i<n;i++) {
	if(a[i]==0&&b[i]==0) {temp++;continue;}
	if(a[i]==0||b[i]==0) continue;
	ll g=__gcd(a[i],b[i]);

	a[i]=a[i]/g;
	b[i]=b[i]/g;
}

map<pair<ll,ll>,ll> m;
map<pair<ll,ll>,ll> :: iterator it;
for(int i=0;i<n;i++){
if(a[i]==0) continue;
	   /// cout<<z<<endl;
	it=m.find(make_pair(a[i],b[i]));
		if(it==m.end()) m.insert(make_pair(make_pair(a[i],b[i]),1));
		else (it->second)++;

}

for(it=m.begin();it!=m.end();it++){
    //cout<<it->first<<" "<<it->second<<endl;
	ans=max(ans,it->second);
}
cout<<ans+temp<<endl;

}


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

int main(){

ll n;
cin>>n;
ll a[n+1],b[n+1];
for(int i=0;i<n;i++) cin>>a[i];
for(int i=0;i<n;i++) cin>>b[i];
ll ans=0,temp=0;
for(int i=0;i<n;i++) {
	if(a[i]==0&&b[i]==0) {temp++;continue;}
	if(a[i]==0||b[i]==0) continue;
	ll g=__gcd(a[i],b[i]);

	a[i]=a[i]/g;
	b[i]=b[i]/g;
}

map<pair<ll,ll>,ll> m;
map<pair<ll,ll>,ll> :: iterator it;
for(int i=0;i<n;i++){
if(a[i]==0) continue;
	   /// cout<<z<<endl;
  if(a[i]>0&&b[i]<0) {
      a[i]=a[i]*-1;
      b[i]=b[i]*-1;
  }
  if(a[i]<0&&b[i]<0){
  	a[i]=a[i]*-1;
      b[i]=b[i]*-1;
  }

	it=m.find(make_pair(a[i],b[i]));
		if(it==m.end()) m.insert(make_pair(make_pair(a[i],b[i]),1));
		else (it->second)++;

}

for(it=m.begin();it!=m.end();it++){
    //cout<<it->first<<" "<<it->second<<endl;
	ans=max(ans,it->second);
}
cout<<ans+temp<<endl;

}


#include<cstdio>
#include<algorithm>
#include<map>
#include<queue>
#include<set>
#include<cmath>
typedef long long ll;
ll read(ll x = 0, ll fr = 1, char ch = getchar())
{
    while (ch < '0'|| ch > '9') {if (ch == '-') fr = -1; ch = getchar();}
    while (ch <= '9' && ch >= '0') x = x * 10 + ch - '0', ch = getchar();
    return x * fr;
}
using namespace std;
int n;
struct data
{
    int x, y;

	bool operator<(const data b) const
	{
		if (x == b.x) return y < b.y;
        else
        {
             return x < b.x;
        }

	}
}a[200050];
int gcd(int a, int b){if (a % b == 0) return b;else return gcd(b, a % b);}
bool cmp(data a, data b)
{
    if (a.x == 0 && b.x != 0) return 1;
    if (a.x != 0 && b.x == 0) return 0;
    if (a.x == 0 && b.x == 0) return 1;
    return (1.0 * a.y)/(1.0 * a.x) <= (1.0 * b.y)/(1.0 * b.x);
}
std :: map<data, int>mp;
int main()
{
    n = read();
    for (int i = 1; i <= n; i++) a[i].x = read();
    for (int i = 1; i <= n; i++)
    {
        a[i].y = read();
        if (a[i].x != 0)
        {
            int tmp = gcd(abs(a[i].x), abs(a[i].y));
            a[i].x /= tmp, a[i].y /= tmp;
            if (a[i].x < 0) a[i].x *= -1, a[i].y *= -1;
        }
        mp[a[i]]++;
    }
    int mx = 0;
    /*std :: sort(a + 1, a + n + 1, cmp);
    int mx = 0, now = 0;
    for(int i = 1; i <= n; i++)
    {
        if (a[i].x == 0) continue;
        if (a[i].x == a[i - 1].x && a[i].y == a[i - 1].y)
            now++, mx = std :: max(now, mx);
        else now = 1, mx = std :: max(mx, now);
    }*/
    for(int i = 1; i <= n; i++)
    {
        if (a[i].x == 0 && a[i].y != 0) continue;
        mx = max(mx, mp[a[i]]);
    }
    printf("%d", mx);
    return 0;
}
/*
3
1 2 1
6 12 -6

*/


#include<cstdio>
#include<algorithm>
#include<map>
#include<queue>
#include<set>
#include<cmath>
typedef long long ll;
ll read(ll x = 0, ll fr = 1, char ch = getchar())
{
    while (ch < '0'|| ch > '9') {if (ch == '-') fr = -1; ch = getchar();}
    while (ch <= '9' && ch >= '0') x = x * 10 + ch - '0', ch = getchar();
    return x * fr;
}
using namespace std;
int n;
struct data
{
    int x, y;

	bool operator<(const data b) const
	{
		if (x == b.x) return y < b.y;
        else
        {
             return x < b.x;
        }

	}
}a[200050];
int gcd(int a, int b){if (a % b == 0) return b;else return gcd(b, a % b);}
std :: map<data, int>mp;
int main()
{
    n = read();
    int s1 = 0, s2 = 0;
    for (int i = 1; i <= n; i++) a[i].x = read();
    for (int i = 1; i <= n; i++)
    {
        a[i].y = read();
        if (a[i].x != 0 && a[i].y != 0)
        {
            int tmp = gcd(abs(a[i].x), abs(a[i].y));
            a[i].x /= tmp, a[i].y /= tmp;
        }
        if (a[i].x < 0) a[i].x *= -1, a[i].y *= -1;
        if (a[i].x != 0 && a[i].y == 0) s2++;
        if (a[i].x == 0 && a[i].y == 0) s1++;
        mp[a[i]]++;
    }
    int mx = s2;
    for(int i = 1; i <= n; i++)
    {
        if (a[i].x == 0 && a[i].y != 0) continue;
        mx = max(mx, mp[a[i]]);
    }
    printf("%d", mx + s1);
    return 0;
}
/*
7
1 2 1 1 2 3 0
6 12 -7 0 0 0 0

*/


#include<cstdio>
#include<algorithm>
#include<map>
#include<queue>
#include<set>
#include<cmath>
typedef long long ll;
ll read(ll x = 0, ll fr = 0, char ch = getchar())
{
    while (ch < '0'|| ch > '9') {if (ch == '-') fr = -1; ch = getchar();}
    while (ch <= '9' && ch >= '0') x = x * 10 + ch - '0', ch = getchar();
    return x;
}
using namespace std;
int n;
struct data
{
    int x, y, flag;
}a[200050];
int gcd(int a, int b)
{
    if (a % b == 0) return b;
    else return gcd(b, a % b);
}
bool cmp(data a, data b)
{
    if (a.x == 0 && b.x != 0) return 1;
    if (a.x != 0 && b.x == 0) return 0;
    if (a.x == 0 && b.x == 0) return 1;
    return (1.0 * a.y)/(1.0 * a.x) <= (1.0 * b.y)/(1.0 * b.x);
}
int main()
{
    n = read();
    for (int i = 1; i <= n; i++)
    {
        a[i].x = read();
    }
    for (int i = 1; i <= n; i++)
    {
        a[i].y = read();
        if (a[i].x == 0) {continue;}
        int tmp = gcd(abs(a[i].x), abs(a[i].y));
        a[i].x /= tmp, a[i].y /= tmp;
    }
    std :: sort(a + 1, a + n + 1, cmp);
    int mx = 0, now = 1;
    for(int i = 2; i <= n; i++)
    {
        if (a[i].x == a[i - 1].x && a[i].y == a[i - 1].y) now++, mx = std :: max(now, mx);
        else now = 1;
    }
    printf("%d", mx);
    return 0;
}


#include<cstdio>
#include<algorithm>
#include<map>
#include<queue>
#include<set>
#include<cmath>
typedef long long ll;
ll read(ll x = 0, ll fr = 1, char ch = getchar())
{
    while (ch < '0'|| ch > '9') {if (ch == '-') fr = -1; ch = getchar();}
    while (ch <= '9' && ch >= '0') x = x * 10 + ch - '0', ch = getchar();
    return x * fr;
}
using namespace std;
int n;
struct data
{
    int x, y;
}a[250];
int gcd(int a, int b){if (a % b == 0) return b;else return gcd(b, a % b);}
bool cmp(data a, data b)
{
    if (a.x == 0 && b.x != 0) return 1;
    if (a.x != 0 && b.x == 0) return 0;
    if (a.x == 0 && b.x == 0) return 1;
    return (1.0 * a.y)/(1.0 * a.x) <= (1.0 * b.y)/(1.0 * b.x);
}
int main()
{
    n = read();
    for (int i = 1; i <= n; i++)
        a[i].x = read();
    for (int i = 1; i <= n; i++)
    {
        a[i].y = read();
        if (a[i].x == 0) {continue;}
        int tmp = gcd(abs(a[i].x), abs(a[i].y));
        a[i].x /= tmp, a[i].y /= tmp;
        if (a[i].x < 0 && a[i].y > 0) a[i].x *= -1, a[i].y *= -1;
        if (a[i].x < 0 && a[i].y < 0) a[i].x *= -1, a[i].y *= -1;
    }
    std :: sort(a + 1, a + n + 1, cmp);
    int mx = 0, now = 1;
    for(int i = 2; i <= n; i++)
    {
        if (a[i].x == a[i - 1].x && a[i].y == a[i - 1].y)
            now++, mx = std :: max(now, mx);
        else now = 1;
    }
    printf("%d", mx);
    return 0;
}
/*
3
1 2 -1
6 12 -6

*/


#include<cstdio>
#include<algorithm>
#include<map>
#include<queue>
#include<set>
#include<cmath>
typedef long long ll;
ll read(ll x = 0, ll fr = 1, char ch = getchar())
{
    while (ch < '0'|| ch > '9') {if (ch == '-') fr = -1; ch = getchar();}
    while (ch <= '9' && ch >= '0') x = x * 10 + ch - '0', ch = getchar();
    return x * fr;
}
using namespace std;
int n;
struct data
{
    int x, y;

	bool operator<(const data b) const
	{
		if (x == b.x) return y < b.y;
        else
        {
             return x < b.x;
        }

	}
}a[200050];
int gcd(int a, int b){if (a % b == 0) return b;else return gcd(b, a % b);}
std :: map<data, int>mp;
int main()
{
    n = read();
    int s1 = 0, s2 = 0;
    for (int i = 1; i <= n; i++) a[i].x = read();
    for (int i = 1; i <= n; i++)
    {
        a[i].y = read();
        if (a[i].x != 0 && a[i].y != 0)
        {
            int tmp = gcd(abs(a[i].x), abs(a[i].y));
            a[i].x /= tmp, a[i].y /= tmp;
        }
        if (a[i].x < 0) a[i].x *= -1, a[i].y *= -1;
        if (a[i].x != 0 && a[i].y == 0) s2++;
        if (a[i].x == 0 && a[i].y == 0) s1++;
        else mp[a[i]]++;
    }
    int mx = 0;
    for(int i = 1; i <= n; i++)
    {
        if (a[i].x == 0 && a[i].y != 0) continue;
        mx = max(mx, mp[a[i]]);
    }
    printf("%d", mx + s1);
    return 0;
}
/*
2
0 0
0 0

*/


#include<cstdio>
#include<algorithm>
#include<map>
#include<queue>
#include<set>
#include<cmath>
typedef long long ll;
ll read(ll x = 0, ll fr = 1, char ch = getchar())
{
    while (ch < '0'|| ch > '9') {if (ch == '-') fr = -1; ch = getchar();}
    while (ch <= '9' && ch >= '0') x = x * 10 + ch - '0', ch = getchar();
    return x * fr;
}
using namespace std;
int n;
struct data
{
    int x, y;
}a[250];
int gcd(int a, int b){if (a % b == 0) return b;else return gcd(b, a % b);}
bool cmp(data a, data b)
{
    if (a.x == 0 && b.x != 0) return 1;
    if (a.x != 0 && b.x == 0) return 0;
    if (a.x == 0 && b.x == 0) return 1;
    return (1.0 * a.y)/(1.0 * a.x) <= (1.0 * b.y)/(1.0 * b.x);
}
int main()
{
    n = read();
    for (int i = 1; i <= n; i++)
        a[i].x = read();
    for (int i = 1; i <= n; i++)
    {
        a[i].y = read();
        if (a[i].x == 0) {continue;}
        int tmp = gcd(abs(a[i].x), abs(a[i].y));
        a[i].x /= tmp, a[i].y /= tmp;
        if (a[i].x < 0) a[i].x *= -1, a[i].y *= -1;
    }
    std :: sort(a + 1, a + n + 1, cmp);
    int mx = 0, now = 1;
    for(int i = 2; i <= n; i++)
    {
        if (a[i].x == a[i - 1].x && a[i].y == a[i - 1].y)
            now++, mx = std :: max(now, mx);
        else now = 1;
    }
    printf("%d", mx);
    return 0;
}
/*
3
1 2 -1
6 12 -6

*/


#include<cstdio>
#include<algorithm>
#include<map>
#include<queue>
#include<set>
#include<cmath>
typedef long long ll;
ll read(ll x = 0, ll fr = 1, char ch = getchar())
{
    while (ch < '0'|| ch > '9') {if (ch == '-') fr = -1; ch = getchar();}
    while (ch <= '9' && ch >= '0') x = x * 10 + ch - '0', ch = getchar();
    return x * fr;
}
using namespace std;
int n;
struct data
{
    int x, y;
}a[250];
int gcd(int a, int b){if (a % b == 0) return b;else return gcd(b, a % b);}
bool cmp(data a, data b)
{
    if (a.x == 0 && b.x != 0) return 1;
    if (a.x != 0 && b.x == 0) return 0;
    if (a.x == 0 && b.x == 0) return 1;
    return (1.0 * a.y)/(1.0 * a.x) <= (1.0 * b.y)/(1.0 * b.x);
}
int main()
{
    n = read();
    for (int i = 1; i <= n; i++) a[i].x = read();
    for (int i = 1; i <= n; i++)
    {
        a[i].y = read();
        if (a[i].x == 0) continue;
        int tmp = gcd(abs(a[i].x), abs(a[i].y));
        a[i].x /= tmp, a[i].y /= tmp;
        if (a[i].x < 0) a[i].x *= -1, a[i].y *= -1;
    }
    std :: sort(a + 1, a + n + 1, cmp);
    int mx = 0, now = 1;
    for(int i = 1; i <= n; i++)
    {
        if (a[i].x == 0) continue;
        if (a[i].x == a[i - 1].x && a[i].y == a[i - 1].y)
            now++, mx = std :: max(now, mx);
        else now = 1, mx = std :: max(mx, now);
    }
    printf("%d", mx);
    return 0;
}
/*
3
1 2 1
6 12 -6

*/


#include<cstdio>
#include<algorithm>
#include<map>
#include<queue>
#include<set>
#include<cmath>
typedef long long ll;
ll read(ll x = 0, ll fr = 1, char ch = getchar())
{
    while (ch < '0'|| ch > '9') {if (ch == '-') fr = -1; ch = getchar();}
    while (ch <= '9' && ch >= '0') x = x * 10 + ch - '0', ch = getchar();
    return x * fr;
}
using namespace std;
int n;
struct data
{
    int x, y;

	bool operator<(const data b) const
	{
		if (x == b.x) return y < b.y;
        else
        {
             return x < b.x;
        }

	}
}a[200050];
int gcd(int a, int b){if (a % b == 0) return b;else return gcd(b, a % b);}
bool cmp(data a, data b)
{
    if (a.x == 0 && b.x != 0) return 1;
    if (a.x != 0 && b.x == 0) return 0;
    if (a.x == 0 && b.x == 0) return 1;
    return (1.0 * a.y)/(1.0 * a.x) <= (1.0 * b.y)/(1.0 * b.x);
}
std :: map<data, int>mp;
int main()
{
    n = read();
    for (int i = 1; i <= n; i++) a[i].x = read();
    for (int i = 1; i <= n; i++)
    {
        a[i].y = read();
        if (a[i].x == 0) continue;
        int tmp = gcd(abs(a[i].x), abs(a[i].y));
        a[i].x /= tmp, a[i].y /= tmp;
        if (a[i].x < 0) a[i].x *= -1, a[i].y *= -1;
        mp[a[i]]++;
    }
    int mx = 0;
    /*std :: sort(a + 1, a + n + 1, cmp);
    int mx = 0, now = 0;
    for(int i = 1; i <= n; i++)
    {
        if (a[i].x == 0) continue;
        if (a[i].x == a[i - 1].x && a[i].y == a[i - 1].y)
            now++, mx = std :: max(now, mx);
        else now = 1, mx = std :: max(mx, now);
    }*/
    for(int i = 1; i <= n; i++)
    {
        if (a[i].x == 0) continue;
        mx = max(mx, mp[a[i]]);
    }
    printf("%d", mx);
    return 0;
}
/*
3
1 2 1
6 12 -6

*/


#include<cstdio>
#include<algorithm>
#include<map>
#include<queue>
#include<set>
#include<cmath>
typedef long long ll;
ll read(ll x = 0, ll fr = 1, char ch = getchar())
{
    while (ch < '0'|| ch > '9') {if (ch == '-') fr = -1; ch = getchar();}
    while (ch <= '9' && ch >= '0') x = x * 10 + ch - '0', ch = getchar();
    return x * fr;
}
using namespace std;
int n;
struct data
{
    int x, y;
}a[250];
int gcd(int a, int b){if (a % b == 0) return b;else return gcd(b, a % b);}
bool cmp(data a, data b)
{
    if (a.x == 0 && b.x != 0) return 1;
    if (a.x != 0 && b.x == 0) return 0;
    if (a.x == 0 && b.x == 0) return 1;
    return (1.0 * a.y)/(1.0 * a.x) <= (1.0 * b.y)/(1.0 * b.x);
}
int main()
{
    n = read();
    for (int i = 1; i <= n; i++) a[i].x = read();
    for (int i = 1; i <= n; i++)
    {
        a[i].y = read();
        if (a[i].x == 0) continue;
        int tmp = gcd(abs(a[i].x), abs(a[i].y));
        a[i].x /= tmp, a[i].y /= tmp;
        if (a[i].x < 0) a[i].x *= -1, a[i].y *= -1;
    }
    std :: sort(a + 1, a + n + 1, cmp);
    int mx = 0, now = 1;
    for(int i = 2; i <= n; i++)
    {
        if (a[i].x == a[i - 1].x && a[i].y == a[i - 1].y)
            now++, mx = std :: max(now, mx);
        else now = 1, mx = std :: max(mx, now);
    }
    printf("%d", mx);
    return 0;
}
/*
3
1 2 1
6 12 -6

*/


#include<cstdio>
#include<algorithm>
#include<map>
#include<queue>
#include<set>
#include<cmath>
typedef long long ll;
ll read(ll x = 0, ll fr = 1, char ch = getchar())
{
    while (ch < '0'|| ch > '9') {if (ch == '-') fr = -1; ch = getchar();}
    while (ch <= '9' && ch >= '0') x = x * 10 + ch - '0', ch = getchar();
    return x * fr;
}
using namespace std;
int n;
struct data
{
    int x, y;
}a[200050];
int gcd(int a, int b){if (a % b == 0) return b;else return gcd(b, a % b);}
bool cmp(data a, data b)
{
    if (a.x == 0 && b.x != 0) return 1;
    if (a.x != 0 && b.x == 0) return 0;
    if (a.x == 0 && b.x == 0) return 1;
    return (1.0 * a.y)/(1.0 * a.x) <= (1.0 * b.y)/(1.0 * b.x);
}
int main()
{
    n = read();
    for (int i = 1; i <= n; i++) a[i].x = read();
    for (int i = 1; i <= n; i++)
    {
        a[i].y = read();
        if (a[i].x == 0) continue;
        int tmp = gcd(abs(a[i].x), abs(a[i].y));
        a[i].x /= tmp, a[i].y /= tmp;
        if (a[i].x < 0) a[i].x *= -1, a[i].y *= -1;
    }
    std :: sort(a + 1, a + n + 1, cmp);
    int mx = 0, now = 0;
    for(int i = 1; i <= n; i++)
    {
        if (a[i].x == 0) continue;
        if (a[i].x == a[i - 1].x && a[i].y == a[i - 1].y)
            now++, mx = std :: max(now, mx);
        else now = 1, mx = std :: max(mx, now);
    }
    printf("%d", mx);
    return 0;
}
/*
3
1 2 1
6 12 -6

*/


#include<cstdio>
#include<algorithm>
#include<map>
#include<queue>
#include<set>
#include<cmath>
#include<iostream>
typedef long long ll;
ll read(ll x = 0, ll fr = 1, char ch = getchar())
{
    while (ch < '0'|| ch > '9') {if (ch == '-') fr = -1; ch = getchar();}
    while (ch <= '9' && ch >= '0') x = x * 10 + ch - '0', ch = getchar();
    return x * fr;
}
using namespace std;
long long a,b,c,d,e,A[200009],B[200009],pas,k;
map <pair<long long, long long>, long long> m;
map <pair<long long, long long>, long long>::iterator it;
int main()
{
	ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	cin>>a;
	for(b=1; b<=a; b++) cin>>A[b];
	for(b=1; b<=a; b++) cin>>B[b];
	for(b=1; b<=a; b++)
    {
		if (B[b] == 0) pas++;
		if (A[b] == 0 && B[b] == 0) k++;
	}
	for(b = 1; b <= a; b++)
    {
		if(A[b] != 0&&B[b] != 0)
        {
			c=__gcd(A[b],B[b]);
			m[make_pair(A[b]/c, B[b]/c)]++;
		}
	}
	for(it=m.begin(); it!=m.end(); it++)
    {
		if((*it).second + k > pas) pas = (*it).second+k;
	}
	cout << pas;
	return 0;
}
/*
2
0 0
0 0

*/