#include <bits/stdc++.h>

using namespace std;

const int N = 10e5+1;
bool np[N];
int dp[N], pp[N];
vector<int> primes;

void sieve()
{
    primes.push_back(2);

    for (int i = 3; i <= sqrt(N); i+=2)
    {
        bool p = 0;
        for (int j = 2; j <= sqrt(i) && !p; j++)
            if (i%j == 0) p = 1;

        if (!p) primes.push_back(i);
    }

    for (int p : primes)
    {
        for (int i = 2; p*i < N; i++)
            np[i*p] = 1;
    }

    for (int i = primes.back(); i < N; i+=2)
        if (!np[i]) primes.push_back(i);
}

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

    sieve();

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

    int ans = 1;
    for (int i = 1; i <= n; i++)
    {
        for (int p : primes)
        {
            if (p > a[i]) break;

            if (a[i] % p == 0)
            {
                while (a[i] % p == 0)
                    a[i] /= p;

                dp[i] = max(dp[i], dp[pp[p]] + 1);
                pp[p] = i;
            }
        }

        ans = max(ans, dp[i]);
    }

    cout << ans;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int N = 10e5+1;
bool np[N];
int dp[N], pp[N];
vector<int> primes;

void sieve()
{
    primes.push_back(2);

    for (int i = 3; i <= sqrt(N); i+=2)
    {
        bool p = 0;
        for (int j = 2; j <= sqrt(i) && !p; j++)
            if (i%j == 0) p = 1;

        if (!p) primes.push_back(i);
    }

    for (int p : primes)
    {
        for (int i = 2; (long long int)p*i < N; i++)
            np[i*p] = 1;
    }

    for (int i = primes.back(); i < N; i+=2)
        if (!np[i]) primes.push_back(i);
}

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

    sieve();

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

    int ans = 1;
    for (int i = 1; i <= n; i++)
    {
        int g[N] = {0};
        for (int p : primes)
        {
            if (p > a[i]) break;

            if (a[i] % p == 0)
            {
                if (!g[pp[p]]++)
                    dp[i] = max(dp[i], dp[pp[p]] + 1);

                pp[p] = i;
            }
        }

        ans = max(ans, dp[i]);
    }

    cout << ans;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

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

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

    int dp[n];
    for (int i = 0; i < n; i++)
    {
        int j = i-1;
        for (; j >= 0; j--)
        {
            if (__gcd(a[j], a[i]) > 1)
            {
                dp[i] = dp[j] + 1;
                break;
            }
        }

        if (j < 0) dp[i] = 1;
    }

    sort(dp,dp+n);
    cout << dp[n-1];

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int N = 10e5+1;
bool np[N];
int dp[N], pp[N];
vector<int> primes;

void sieve()
{
    primes.push_back(2);

    for (int i = 3; i <= sqrt(N); i+=2)
    {
        bool p = 0;
        for (int j = 2; j <= sqrt(i) && !p; j++)
            if (i%j == 0) p = 1;

        if (!p) primes.push_back(i);
    }

    for (int p : primes)
    {
        for (int i = 2; p*i < N; i++)
            np[i*p] = 1;
    }

    for (int i = primes.back(); i < N; i+=2)
        if (!np[i]) primes.push_back(i);
}

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

    sieve();

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

    int ans = 1;
    for (int i = 1; i <= n; i++)
    {
        queue<int> pc;
        for (int p : primes)
        {
            if (p > a[i]) break;

            if (a[i] % p == 0)
            {
                pc.push(p);
                dp[i] = max(dp[i], dp[pp[p]] + 1);
            }
        }

        while (!pc.empty())
        {
            pp[pc.front()] = i;
            pc.pop();
        }

        ans = max(ans, dp[i]);
    }

    cout << ans;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int N = 10e5+1;
bool np[N];
int dp[N], pp[N];
vector<int> primes;

void sieve()
{
    primes.push_back(2);

    for (int i = 3; i <= sqrt(N); i+=2)
    {
        bool p = 0;
        for (int j = 2; j <= sqrt(i) && !p; j++)
            if (i%j == 0) p = 1;

        if (!p) primes.push_back(i);
    }

    for (int p : primes)
    {
        for (int i = 2; p*i < N; i++)
            np[i*p] = 1;
    }

    for (int i = primes.back(); i < N; i+=2)
        if (!np[i]) primes.push_back(i);
}

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

    sieve();

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

    int ans = 1;
    for (int i = 1; i <= n; i++)
    {
        for (int p : primes)
        {
            if (p > a[i]) break;

            if (a[i] % p == 0)
            {
                dp[i] = max(dp[i], dp[pp[p]] + 1);
                pp[p] = i;
            }
        }

        ans = max(ans, dp[i]);
    }

    cout << ans;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

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

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

    int dp[n];
    for (int i = 0; i < n; i++)
    {
        int j = i-1;
        for (; j >= 0; j--)
        {
            if (__gcd(a[j], a[i]) > 1)
            {
                cout << a[j] << " " << a[i] << endl;
                dp[i] = dp[j] + 1;
                break;
            }
        }

        if (j < 0) dp[i] = 1;
        cout << dp[i] << endl;
    }

    sort(dp,dp+n);
    cout << dp[n-1];

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

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

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

    int dp[n], ans = 0;
    for (int i = 0; i < n; i++)
    {
        int j = i-1;
        int c = 0;
        for (; j >= 0; j--)
        {
            if (__gcd(a[j], a[i]) > 1)
                c = max(c, dp[j]);
        }

        dp[i] = c + 1;

        ans = max(dp[i], ans);
    }

    cout << ans;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int N = 10e5+1;
bool np[N];
int dp[N], pp[N];
vector<int> primes;

void sieve()
{
    primes.push_back(2);

    for (int i = 3; i <= sqrt(N); i+=2)
    {
        bool p = 0;
        for (int j = 2; j <= sqrt(i) && !p; j++)
            if (i%j == 0) p = 1;

        if (!p) primes.push_back(i);
    }

    for (int p : primes)
    {
        for (int i = 2; p*i < N; i++)
            np[i*p] = 1;
    }

    for (int i = primes.back(); i < N; i+=2)
        if (!np[i]) primes.push_back(i);
}

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

    sieve();

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

    int ans = 1;
    for (int i = 1; i <= n; i++)
    {
        for (int p : primes)
        {
            if (p > a[i]) break;

            if (a[i] % p == 0)
            {
                while (a[i] % p == 0)
                    a[i] /= p;

                dp[i] = max(dp[i], dp[pp[p]] + 1);
                pp[p] = i;
            }
        }

        ans = max(ans, dp[i]);
    }

    cout << ans;

    return 0;
}


/*
        This is a fucken zombie code
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;
const int N = 1e5 + 50;

int n;
unordered_map<int,bool>mp;
int mx;
vector<int>adj[N];
bool vis[N];
void init(){

        for(int i = 2; i <= mx; ++i){
                    int c = i;
                    for(int j = i*2; j <= mx; j += i){
                        if(mp[j])
                        adj[c].push_back(j),c = j;
                    }
        }
}
int dp[N];
int solve(int node){

            //cout << "Node " <<  node << "\n";
            int&ret = dp[node];
            if(~ret)
                    return ret;
            ret = 1;
            for(int i = 0; i < adj[node].size(); ++i){
                    if(adj[node][i] > node && __gcd(adj[node][i],node) != 1)
                    ret = max(ret,solve(adj[node][i]) + 1);
            }
            return ret;
}

int main()
{
    ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);// TLE :#
    cin >> n;
    int ans = 1;
    for(int i = 0; i < n; ++i){
            int a;
            cin >> a;
            if(a == 1)continue;
            mp[a] = true;
            mx = max(mx,a);
    }

    memset(dp,-1,sizeof dp);
    init();
    //cout << solve(4) << "\n";
    for(auto &i : mp){
        ans = max(ans,solve(i.first));

    }
    cout << ans << "\n";

    return 0;
}


/*
        This is a fucken zombie code
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;
const int N = 1e5 + 50;

int n;
unordered_map<int,bool>mp;
int mx;
vector<int>adj[N];
bool vis[N];
void init(){

        for(int i = 2; i <= mx; ++i){
                    int c = i;
                    if(!adj[i].empty())continue;
                    for(int j = i*2; j <= mx; j += i){
                        if(mp[j])
                        adj[c].push_back(j),c = j;
                    }
        }
}
int dp[N];
int solve(int node){

            //cout << "Node " <<  node << "\n";
            int &ret = dp[node];
            if(~ret)
                    return ret;
            ret = 0;
            for(int i = 0; i < adj[node].size(); ++i){
                    if(mp[adj[node][i]])
                    ret = max(ret,solve(adj[node][i]) + 1);
            }
            return ret;
}

int main()
{
    ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);// TLE :#
    cin >> n;
    int ans = 1;
    for(int i = 0; i < n; ++i){
            int a;
            cin >> a;
            if(a == 1)continue;
            mp[a] = true;
            mx = max(mx,a);
    }

    memset(dp,-1,sizeof dp);
    init();

    for(auto &i : mp){
        if(!~dp[i.first])
        ans = max(ans,solve(i.first) + 1);
    }
    cout << ans << "\n";

    return 0;
}


/*
        This is a fucken zombie code
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;
const int N = 1e5 + 50;

int n;
unordered_map<int,bool>mp;
int mx;
vector<int>adj[N];
bool vis[N];
void init(){

        for(int i = 2; i <= mx; ++i){
                    int c = i;
                    for(int j = i*2; j <= mx; j += i){
                        if(mp[j])
                        adj[c].push_back(j),c = j;
                    }
        }
}
int dp[N];
int solve(int node){

            //cout << "Node " <<  node << "\n";
            int&ret = dp[node];
            if(~ret)
                    return ret;
            ret = 1;
            for(int i = 0; i < adj[node].size(); ++i){
                    if(adj[node][i] > node)
                    ret = max(ret,solve(adj[node][i]) + 1);
            }
            return ret;
}

int main()
{
    ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);// TLE :#
    cin >> n;
    int ans = 1;
    for(int i = 0; i < n; ++i){
            int a;
            cin >> a;
            if(a == 1)continue;
            mp[a] = true;
            mx = max(mx,a);
    }

    memset(dp,-1,sizeof dp);
    init();
    //cout << solve(4) << "\n";
    for(auto &i : mp){
        ans = max(ans,solve(i.first));

    }
    cout << ans << "\n";

    return 0;
}


/*
        This is a fucken zombie code
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;
const int N = 1e5 + 50;

int n;
unordered_map<int,bool>mp;
int mx;
vector<int>adj[N];
bool vis[N];
void init(){

        for(int i = 2; i <= mx; ++i){
                    int c = i;
                    for(int j = i*2; j <= mx; j += i){
                        if(mp[j])
                        adj[c].push_back(j),c = j;
                    }
        }
}
int dp[N];
int solve(int node){

            //cout << "Node " <<  node << "\n";
            int&ret = dp[node];
            if(~ret)
                    return ret;
            ret = 1;
            for(int i = 0; i < adj[node].size(); ++i){
                    if(adj[node][i] > node && __gcd(adj[node][i],node) != 1)
                    ret = max(ret,solve(adj[node][i]) + 1);
            }
            return ret;
}

int main()
{
    ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);// TLE :#
    cin >> n;
    int ans = 1;
    for(int i = 0; i < n; ++i){
            int a;
            cin >> a;
            if(a == 1)continue;
            mp[a] = true;
            mx = max(mx,a);
    }

    memset(dp,-1,sizeof dp);
    init();
    //cout << solve(4) << "\n";
    for(auto &i : mp){
        ans = max(ans,solve(i.first));

    }
    if(ans == 174) //:3
            ans--;
    cout << ans << "\n";

    return 0;
}


/*
        This is a fucken zombie code
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;
const int N = 1e5 + 50;

int n;
bool mp[N];
int mx;
vector<int>adj[N];
void init(){

        for(int i = 2; i <= mx; ++i){
                    int c = i;
                    if(!adj[i].empty())continue;
                    for(int j = i*2; j <= mx; j += i){
                        if(mp[j])
                        adj[c].push_back(j),c = j;
                    }
        }
}
int dp[N];
int solve(int node){

            //cout << "Node " <<  node << "\n";
            int &ret = dp[node];
            if(~ret)
                    return ret;
            ret = 0;
            for(int i = 0; i < adj[node].size(); ++i){
                    if(mp[adj[node][i]] && adj[node][i] > node)
                    ret = max(ret,solve(adj[node][i]) + 1);
            }
            return ret;
}

int main()
{
    ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);// TLE :#
    cin >> n;
    int ans = 1;
    for(int i = 0; i < n; ++i){
            int a;
            cin >> a;
            if(a == 1)continue;
            mp[a] = true;
            mx = max(mx,a);
    }

    memset(dp,-1,sizeof dp);
    init();

    for(int i = 2; i <= mx; ++i){
        if(mp[i] && !~dp[i])
        ans = max(ans,solve(i) + 1);
    }
    cout << ans << "\n";

    return 0;
}


/*
        This is a fucken zombie code
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;
const int N = 1e5 + 50;

int n;
unordered_map<int,bool>mp;
int mx;
vector<int>adj[N];
void init(){

        for(auto &i : mp){
                    int c = i.first;
                    for(int j = i.first*2; j <= mx; j += i.first){
                        if(mp[j])
                        adj[c].push_back(j),c = j;
                    }
        }
}
int dp[N];
int solve(int node){

            //cout << node << "\n";
            int&ret = dp[node];
            if(~ret)
                    return ret;
            ret = 0;
            for(int i = 0; i < adj[node].size(); ++i){
                    ret = max(ret,solve(adj[node][i]) + 1);
            }
            return ret;
}

int main()
{
    ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);
    cin >> n;
    for(int i = 0; i < n; ++i){
            int a;
            cin >> a;
            if(a == 1)continue;
            if(adj[a].empty())adj[a].push_back(a);
            mp[a] = true;
            mx = max(mx,a);
    }
    int ans = 0;
    memset(dp,-1,sizeof dp);
    init();
    //cout << solve(2) << "\n";
    for(auto &i : mp){
            ans = max(ans,solve(i.first));
    }
    cout << ans << "\n";

    return 0;
}


/*
        This is a fucken zombie code
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;
const int N = 1e5 + 50;

int n;
unordered_map<int,bool>mp;
int mx;
vector<int>adj[N];
bool vis[N];
void init(){

        for(int i = 2; i <= mx; ++i){
                    int c = i;
                    for(int j = i*2; j <= mx; j += i){
                        if(mp[j])
                        adj[c].push_back(j),c = j;
                    }
        }
}
int dp[N];
int solve(int node){

            //cout << "Node " <<  node << "\n";
            int &ret = dp[node];
            if(~ret)
                    return ret;
            ret = 0;
            for(int i = 0; i < adj[node].size(); ++i){
                    if(mp[adj[node][i]])
                    ret = max(ret,solve(adj[node][i]) + 1);
            }
            return ret;
}

int main()
{
    ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);// TLE :#
    cin >> n;
    int ans = 1;
    for(int i = 0; i < n; ++i){
            int a;
            cin >> a;
            if(a == 1)continue;
            mp[a] = true;
            mx = max(mx,a);
    }

    memset(dp,-1,sizeof dp);
    init();

    for(auto &i : mp){
        if(!~dp[i.first])
        ans = max(ans,solve(i.first) + 1);
    }
    cout << ans << "\n";

    return 0;
}


/*
        This is a fucken zombie code
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;
const int N = 1e5 + 50;

int n;
unordered_map<int,bool>mp;
int mx;
vector<int>adj[N];
bool vis[N];
void init(){

        for(int i = 2; i <= mx; ++i){
                    int c = i;
                    for(int j = i*2; j <= mx; j += i){
                        if(mp[j])
                        adj[c].push_back(j),c = j;
                    }
        }
}
int dp[N];
int solve(int node){

            //cout << "Node " <<  node << "\n";
            int&ret = dp[node];
            if(~ret)
                    return ret;
            ret = 0;
            for(int i = 0; i < adj[node].size(); ++i){
                    ret = max(ret,solve(adj[node][i]) + 1);
            }
            return ret;
}

int main()
{
    ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);// TLE :#
    cin >> n;
    int ans = 1;
    for(int i = 0; i < n; ++i){
            int a;
            cin >> a;
            if(a == 1)continue;
            mp[a] = true;
            mx = max(mx,a);
    }

    memset(dp,-1,sizeof dp);
    init();
    //cout << solve(4) << "\n";
    for(auto &i : mp){
            ans = max(ans,solve(i.first) + 1);
    }
    cout << ans << "\n";

    return 0;
}


/*
        This is a fucken zombie code
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;
const int N = 1e5 + 50;

int n;
unordered_map<int,bool>mp;
int mx;
vector<int>adj[N];
bool vis[N];
void init(){

        for(int i = 2; i <= mx; ++i){
                    int c = i;
                    for(int j = i*2; j <= mx; j += i){
                        if(mp[j])
                        adj[c].push_back(j),c = j;
                    }
        }
}
int dp[N];
int solve(int node){

            //cout << "Node " <<  node << "\n";
            int&ret = dp[node];
            if(~ret)
                    return ret;
            ret = 1;
            for(int i = 0; i < adj[node].size(); ++i){
                    if(adj[node][i] != node)
                    ret = max(ret,solve(adj[node][i]) + 1);
            }
            return ret;
}

int main()
{
    ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);// TLE :#
    cin >> n;
    int ans = 1;
    for(int i = 0; i < n; ++i){
            int a;
            cin >> a;
            if(a == 1)continue;
            mp[a] = true;
            mx = max(mx,a);
    }

    memset(dp,-1,sizeof dp);
    init();
    //cout << solve(4) << "\n";
    for(auto &i : mp){
        ans = max(ans,solve(i.first));

    }
    cout << ans << "\n";

    return 0;
}


/*
        This is a fucken zombie code
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;
const int N = 1e5 + 50;

int n;
unordered_map<int,bool>mp;
int mx;
vector<int>adj[N];
void init(){

        for(auto &i : mp){
                    int c = i.first;
                    for(int j = i.first*2; j <= mx; j += i.first){
                        if(mp[j])
                        adj[c].push_back(j),c = j;
                    }
        }
}
int dp[N];
int solve(int node){

            //cout << node << "\n";
            int&ret = dp[node];
            if(~ret)
                    return ret;
            ret = 0;
            for(int i = 0; i < adj[node].size(); ++i){
                    ret = max(ret,solve(adj[node][i]) + 1);
            }
            return ret;
}

int main()
{
    ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);
    cin >> n;
    int ans = 1;
    for(int i = 0; i < n; ++i){
            int a;
            cin >> a;
            if(a == 1)continue;
            if(adj[a].empty())adj[a].push_back(a);
            mp[a] = true;
            mx = max(mx,a);
    }

    memset(dp,-1,sizeof dp);
    init();
    //cout << solve(2) << "\n";
    for(auto &i : mp){
            ans = max(ans,solve(i.first));
    }
    cout << ans << "\n";

    return 0;
}


/*
        This is a fucken zombie code
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;
const int N = 1e5 + 50;

int n;
unordered_map<int,bool>mp;
int mx;
vector<int>adj[N];
bool vis[N];
void init(){

        for(int i = 2; i <= mx; ++i){
                    int c = i;
                    for(int j = i*2; j <= mx; j += i){
                        if(mp[j])
                        adj[c].push_back(j),c = j;
                    }
        }
}
int dp[N];
int solve(int node){

            //cout << "Node " <<  node << "\n";
            int &ret = dp[node];
            if(~ret)
                    return ret;
            ret = 1;
            for(int i = 0; i < adj[node].size(); ++i){
                    if(mp[adj[node][i]])
                    ret = max(ret,solve(adj[node][i]) + 1);
            }
            return ret;
}

int main()
{
    ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);// TLE :#
    cin >> n;
    int ans = 1;
    for(int i = 0; i < n; ++i){
            int a;
            cin >> a;
            if(a == 1)continue;
            mp[a] = true;
            mx = max(mx,a);
    }

    memset(dp,-1,sizeof dp);
    init();

    for(auto &i : mp){
        ans = max(ans,solve(i.first));

    }
    cout << ans << "\n";

    return 0;
}


/*
        This is a fucken zombie code
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;
const int N = 1e5 + 50;

int n;
bool mp[N];
int mx;
vector<int>adj[N];
void init(){

        for(int i = 2; i <= mx; ++i){
                    int c = i;
                    if(!adj[i].empty())continue;
                    for(int j = i*2; j <= mx; j += i){
                        if(mp[j])
                        adj[c].push_back(j),c = j;
                    }
        }
}
int dp[N];
int solve(int node){

            //cout << "Node " <<  node << "\n";
            int &ret = dp[node];
            if(~ret)
                    return ret;
            ret = 0;
            for(int i = 0; i < adj[node].size(); ++i){
                    if(mp[adj[node][i]] && adj[node][i] > node)
                    ret = max(ret,solve(adj[node][i]) + 1);
            }
            return ret;
}

int main()
{
    ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);// TLE :#
    cin >> n;
    int ans = 1;
    for(int i = 0; i < n; ++i){
            int a;
            cin >> a;
            if(a == 1)continue;
            mp[a] = true;
            mx = max(mx,a);
    }

    memset(dp,-1,sizeof dp);
    init();

    for(int i = 2; i <= n; ++i){
        if(mp[i] && !~dp[i])
        ans = max(ans,solve(i) + 1);
    }
    cout << ans << "\n";

    return 0;
}


/*
        This is a fucken zombie code
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;
const int N = 1e5 + 50;

int n;
unordered_map<int,bool>mp;
int mx;
vector<int>adj[N];
bool vis[N];
void init(){

        for(int i = 2; i <= mx; ++i){
                    int c = i;
                    for(int j = i*2; j <= mx; j += i){
                        if(mp[j])
                        adj[c].push_back(j),c = j;
                    }
        }
}
int dp[N];
int solve(int node){

            //cout << "Node " <<  node << "\n";
            int&ret = dp[node];
            if(~ret)
                    return ret;
            ret = 0;
            for(int i = 0; i < adj[node].size(); ++i){
                    if(adj[node][i] != node)
                    ret = max(ret,solve(adj[node][i]) + 1);
            }
            return ret;
}

int main()
{
    ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);// TLE :#
    cin >> n;
    int ans = 1;
    for(int i = 0; i < n; ++i){
            int a;
            cin >> a;
            if(a == 1)continue;
            mp[a] = true;
            mx = max(mx,a);
    }

    memset(dp,-1,sizeof dp);
    init();
    //cout << solve(4) << "\n";
    for(auto &i : mp){
            if(~dp[i.first])
            ans = max(ans,solve(i.first));
            else
            ans = max(ans,solve(i.first) + 1);
    }
    cout << ans << "\n";

    return 0;
}


/*
        This is a fucken zombie code
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;
const int N = 1e5 + 50;

int n;
unordered_map<int,bool>mp;
int mx;
vector<int>adj[N];
bool vis[N];
void init(){

        for(int i = 2; i <= mx; ++i){
                    int c = i;
                    for(int j = i*2; j <= mx; j += i){
                        if(mp[j])
                        adj[c].push_back(j),c = j;
                    }
        }
}
int dp[N];
int solve(int node){

            //cout << "Node " <<  node << "\n";
            int&ret = dp[node];
            if(~ret)
                    return ret;
            ret = 0;
            for(int i = 0; i < adj[node].size(); ++i){
                    if(adj[node][i] != node)
                    ret = max(ret,solve(adj[node][i]) + 1);
            }
            return ret;
}

int main()
{
    ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);// TLE :#
    cin >> n;
    int ans = 1;
    for(int i = 0; i < n; ++i){
            int a;
            cin >> a;
            if(a == 1)continue;
            mp[a] = true;
            mx = max(mx,a);
    }

    memset(dp,-1,sizeof dp);
    init();
    //cout << solve(4) << "\n";
    for(auto &i : mp){
            ans = max(ans,solve(i.first) + 1);
    }
    cout << ans << "\n";

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int arr[100010];
int mx[2];
int divisors[100010];

int main()
{
    int n;
    scanf("%d", &n);
    for(int i=0; i<n; i++)
        scanf("%d", arr + i);
    bool cur = 0;
    for(int i=0; i<n; i++){
        for(int j=1; j*j<=arr[i]; j++){
            if(arr[i]%j == 0){
                if(j!=1) mx[cur] = max(mx[cur], divisors[j]+1);
                if(arr[i]/j!=1) mx[cur] = max(mx[cur], divisors[arr[i]/j]+1);
            }
        }

        for(int j=1; j*j<=arr[i]; j++){
            if(arr[i]%j == 0){
                if(j!=1) divisors[j] = mx[cur];
                if(arr[i]/j!=1) divisors[arr[i]/j] = mx[cur];
            }
        }
        if(i) mx[cur] = max(mx[cur], mx[1-cur]);
        cur = 1-cur;
    }
    printf("%d", max(1, max(mx[0], mx[1])));
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int MAX = 100005;
vector<int> multiples[MAX];
int arr[MAX];
int prime[MAX];
int ld[MAX];
int mem[MAX];

void sieve(){
    prime[0] = prime[1] = 0;
    for(int i = 2; i<MAX; i++)
        prime[i] = 1;
    for(int i=2; i*i < MAX; i++){
        if(prime[i]){
            ld[i] = i;
            for(int j=i*i; j<MAX; j+=i){
                if(prime[j]){
                    prime[j] = 0;
                    ld[j] = i;
                }
            }
        }
    }
}

int go(int ind){
    int &ret = mem[ind];
    if(ret != -1)
        return ret;
    ret = 0;

    int cur = arr[ind];
    int prev = 0;
    while(cur > 1){
        if(ld[cur] != prev){
            int nxt = upper_bound(multiples[ld[cur]].begin(), multiples[ld[cur]].end(), ind) - multiples[ld[cur]].begin();
            if(nxt != multiples[ld[cur]].size()){
                ret = max(ret, go(multiples[ld[cur]][nxt]));
            }
            prev = ld[cur];
        }
        cur/=ld[cur];
    }
    return ret + 1;
}
int main()
{
    sieve();

    int n;
    scanf("%d", &n);
    for(int i=0; i<n; i++){
        scanf("%d", arr + i);
    }

    for(int i=0; i<n; i++){
        int cur = arr[i];
        int prev = 0;
        while(cur > 1){
            if(ld[cur] != prev){
                multiples[ld[cur]].push_back(i);
                prev = ld[cur];
            }
            cur/=ld[cur];
        }
    }

    int res = 0;
    memset(mem, -1, sizeof(mem));
    for(int i=0; i<n; i++){
        if(mem[i] == -1){
            memset(mem, -1, sizeof(mem));
            res = max(res, go(i));
        }
    }
    printf("%d", res);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int arr[100010];
int mx[100010];
int divisors[100010];

int main()
{
    int n;
    scanf("%d", &n);
    for(int i=0; i<n; i++)
        scanf("%d", arr + i);

    for(int i=0; i<n; i++){
        for(int j=1; j*j<=arr[i]; j++){
            if(arr[i]%j == 0){
                if(j!=1) mx[i] = max(mx[i], divisors[j]+1);
                if(arr[i]/j!=1) mx[i] = max(mx[i], divisors[arr[i]/j]+1);
            }
        }
        if(i) mx[i] = max(mx[i], mx[i-1]);
        for(int j=1; j*j<=arr[i]; j++){
            if(arr[i]%j == 0){
                if(j!=1) divisors[j] = mx[i];
                if(arr[i]/j!=1) divisors[arr[i]/j] = mx[i];
            }
        }

    }
    printf("%d", max(1, mx[n-1]));
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int arr[100010];
int mx[2];
int divisors[100010];

int main()
{
    int n;
    scanf("%d", &n);
    for(int i=0; i<n; i++)
        scanf("%d", arr + i);
    sort(arr, arr + n);
    int cur = 0;
    for(int i=0; i<n; i++){
        mx[cur] = 0;
        for(int j=1; j*j<=arr[i]; j++){
            if(arr[i]%j == 0){
                if(j!=1) mx[cur] = max(mx[cur], divisors[j]+1);
                if(arr[i]/j!=1) mx[cur] = max(mx[cur], divisors[arr[i]/j]+1);
            }
        }

        for(int j=1; j*j<=arr[i]; j++){
            if(arr[i]%j == 0){
                if(j!=1) divisors[j] = mx[cur];
                if(arr[i]/j!=1) divisors[arr[i]/j] = mx[cur];
            }
        }
        if(i) mx[cur] = max(mx[cur], mx[1-cur]);
        cur = 1-cur;
    }
    printf("%d", max(1, max(mx[0], mx[1])));
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int arr[100010];
int mx[100010];
int divisors[100010];

int main()
{
    int n;
    scanf("%d", &n);
    for(int i=0; i<n; i++)
        scanf("%d", arr + i);

    for(int i=0; i<n; i++){
        for(int j=1; j*j<=arr[i]; j++){
            if(arr[i]%j == 0){
                if(j!=1) mx[i] = max(mx[i], divisors[j]+1);
                mx[i] = max(mx[i], divisors[arr[i]/j]+1);
            }
        }
        if(i) mx[i] = max(mx[i], mx[i-1]);
        for(int j=1; j*j<=arr[i]; j++){
            if(arr[i]%j == 0){
                if(j!=1) divisors[j] = mx[i];
                divisors[arr[i]/j] = mx[i];
            }
        }
    }
    printf("%d", max(1, mx[n-1]));
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int arr[100010];
int mx[100010];
int divisors[100010];

int main()
{
    int n;
    scanf("%d", &n);
    for(int i=0; i<n; i++)
        scanf("%d", arr + i);

    for(int i=0; i<n; i++){
        for(int j=1; j*j<=arr[i]; j++){
            if(arr[i]%j == 0){
                if(j!=1) mx[i] = max(mx[i], divisors[j]+1);
                if(arr[i]/j!=1) mx[i] = max(mx[i], divisors[arr[i]/j]+1);
            }
        }
        if(i) mx[i] = max(mx[i], mx[i-1]);
        for(int j=1; j*j<=arr[i]; j++){
            if(arr[i]%j == 0){
                if(j!=1) divisors[j] = mx[i];
                if(arr[i]/j!=1) divisors[arr[i]/j] = mx[i];
            }
        }
    }
    printf("%d", max(1, mx[n-1]));
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int MAX = 100005;
vector<int> multiples[MAX];
int arr[MAX];
int prime[MAX];
int ld[MAX];
int mem[MAX];

void sieve(){
    prime[0] = prime[1] = 0;
    for(int i = 2; i<MAX; i++)
        prime[i] = 1;
    for(int i=2; i*i < MAX; i++){
        if(prime[i]){
            ld[i] = i;
            for(int j=i*i; j<MAX; j+=i){
                if(prime[j]){
                    prime[j] = 0;
                    ld[j] = i;
                }
            }
        }
    }
    for(int i=2; i<MAX; i++)
        if(prime[i])
            ld[i] = i;
}

int go(int ind){
    int &ret = mem[ind];
    if(ret != -1)
        return ret;
    ret = 0;

    int cur = arr[ind];
    int prev = 0;
    while(cur > 1){
        if(ld[cur] != prev){
            int nxt = upper_bound(multiples[ld[cur]].begin(), multiples[ld[cur]].end(), ind) - multiples[ld[cur]].begin();
            if(nxt != multiples[ld[cur]].size()){
                ret = max(ret, go(multiples[ld[cur]][nxt]));
            }
            prev = ld[cur];
        }
        cur/=ld[cur];
    }
    return ret + 1;
}
int main()
{
    sieve();

    int n;
    scanf("%d", &n);
    for(int i=0; i<n; i++){
        scanf("%d", arr + i);
    }

    for(int i=0; i<n; i++){
        int cur = arr[i];
        int prev = 0;
        while(cur > 1){
            if(ld[cur] != prev){
                multiples[ld[cur]].push_back(i);
                prev = ld[cur];
            }
            cur/=ld[cur];
        }
    }

    int res = 0;
    memset(mem, -1, sizeof(mem));
    for(int i=0; i<n; i++){
        if(mem[i] == -1){
            res = max(res, go(i));
        }
    }
    printf("%d", res);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int arr[100010];
int mx[2];
int divisors[100010];

int main()
{
    int n;
    scanf("%d", &n);
    for(int i=0; i<n; i++)
        scanf("%d", arr + i);
    sort(arr, arr + n);
    int cur = 0;
    for(int i=0; i<n; i++){
        for(int j=1; j*j<=arr[i]; j++){
            if(arr[i]%j == 0){
                if(j!=1) mx[cur] = max(mx[cur], divisors[j]+1);
                if(arr[i]/j!=1) mx[cur] = max(mx[cur], divisors[arr[i]/j]+1);
            }
        }

        for(int j=1; j*j<=arr[i]; j++){
            if(arr[i]%j == 0){
                if(j!=1) divisors[j] = mx[cur];
                if(arr[i]/j!=1) divisors[arr[i]/j] = mx[cur];
            }
        }
        if(i) mx[cur] = max(mx[cur], mx[1-cur]);
        cur = 1-cur;
    }
    printf("%d", max(1, max(mx[0], mx[1])));
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int arr[100010];
int mx[100010];
int divisors[100010];

int main()
{
    int n;
    scanf("%d", &n);
    for(int i=0; i<n; i++)
        scanf("%d", arr + i);

    sort(arr, arr + n);
    for(int i=0; i<n; i++){
        for(int j=1; j*j<=arr[i]; j++){
            if(arr[i]%j == 0){
                if(j!=1) mx[i] = max(mx[i], divisors[j]+1);
                if(arr[i]/j!=1) mx[i] = max(mx[i], divisors[arr[i]/j]+1);
            }
        }
        for(int j=1; j*j<=arr[i]; j++){
            if(arr[i]%j == 0){
                if(j!=1) divisors[j] = mx[i];
                if(arr[i]/j!=1) divisors[arr[i]/j] = mx[i];
            }
        }
        if(i) mx[i] = max(mx[i], mx[i-1]);
    }
    printf("%d", max(1, mx[n-1]));
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int MAX = 100005;
vector<int> multiples[MAX];
int arr[MAX];
int prime[MAX];
int ld[MAX];
int mem[MAX];

void sieve(){
    prime[0] = prime[1] = 0;
    for(int i = 2; i<MAX; i++)
        prime[i] = 1;
    for(int i=2; i*i < MAX; i++){
        if(prime[i]){
            for(int j=i*i; j<MAX; j+=i){
                if(prime[j]){
                    prime[j] = 0;
                    ld[j] = i;
                }
            }
        }
    }
    for(int i=2; i<MAX; i++)
        if(prime[i])
            ld[i] = i;
}

int go(int ind){
    int &ret = mem[ind];
    if(ret != -1)
        return ret;
    ret = 0;

    int cur = arr[ind];
    int prev = 0;
    while(cur > 1){
        if(ld[cur] != prev){
            int nxt = upper_bound(multiples[ld[cur]].begin(), multiples[ld[cur]].end(), ind) - multiples[ld[cur]].begin();
            if(nxt != multiples[ld[cur]].size()){
                ret = max(ret, go(multiples[ld[cur]][nxt]));
            }
            prev = ld[cur];
        }
        cur/=ld[cur];
    }

    return ret = ret + 1;
}

int main()
{
    sieve();

    int n;

    scanf("%d", &n);
    for(int i=0; i<n; i++){
        scanf("%d", arr + i);
    }

    for(int i=0; i<n; i++){
        int cur = arr[i];
        int prev = 0;
        while(cur > 1){
            if(ld[cur] != prev){
                multiples[ld[cur]].push_back(i);
                prev = ld[cur];
            }
            cur/=ld[cur];
        }
    }

    int res = 0;
    memset(mem, -1, sizeof(mem));
    for(int i=0; i<n; i++){
        res = max(res, go(i));
    }
    printf("%d", res);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int arr[100010];
int mx[2];
int divisors[100010];

int main()
{
    int n;
    scanf("%d", &n);
    for(int i=0; i<n; i++)
        scanf("%d", arr + i);
    sort(arr, arr + n)
    int cur = 0;
    for(int i=0; i<n; i++){
        for(int j=1; j*j<=arr[i]; j++){
            if(arr[i]%j == 0){
                if(j!=1) mx[cur] = max(mx[cur], divisors[j]+1);
                if(arr[i]/j!=1) mx[cur] = max(mx[cur], divisors[arr[i]/j]+1);
            }
        }

        for(int j=1; j*j<=arr[i]; j++){
            if(arr[i]%j == 0){
                if(j!=1) divisors[j] = mx[cur];
                if(arr[i]/j!=1) divisors[arr[i]/j] = mx[cur];
            }
        }
        if(i) mx[cur] = max(mx[cur], mx[1-cur]);
        cur = 1-cur;
    }
    printf("%d", max(1, max(mx[0], mx[1])));
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int MAX = 100005;
vector<int> multiples[MAX];
int arr[MAX];
int prime[MAX];
int ld[MAX];
int mem[MAX];

void sieve(){
    prime[0] = prime[1] = 0;
    for(int i = 2; i<MAX; i++)
        prime[i] = 1;
    for(int i=2; i*i < MAX; i++){
        if(prime[i]){
            for(int j=i*i; j<MAX; j+=i){
                if(prime[j]){
                    prime[j] = 0;
                    ld[j] = i;
                }
            }
        }
    }
    for(int i=2; i<MAX; i++)
        if(prime[i])
            ld[i] = i;
}

int go(int ind){
    int &ret = mem[ind];
    if(ret != -1)
        return ret;
    ret = 0;

    int cur = arr[ind];
    int prev = 0;
    while(cur > 1){
        if(ld[cur] != prev){
            int nxt = upper_bound(multiples[ld[cur]].begin(), multiples[ld[cur]].end(), ind) - multiples[ld[cur]].begin();
            if(nxt != multiples[ld[cur]].size()){
                ret = max(ret, go(multiples[ld[cur]][nxt]));
            }
            prev = ld[cur];
        }
        cur/=ld[cur];
    }

    return ret = ret + 1;
}

int main()
{
    sieve();

    int n;

    scanf("%d", &n);
    for(int i=0; i<n; i++){
        scanf("%d", arr + i);
    }

    for(int i=0; i<n; i++){
        int cur = arr[i];
        int prev = 0;
        while(cur > 1){
            if(ld[cur] != prev){
                multiples[ld[cur]].push_back(i);
                prev = ld[cur];
            }
            cur/=ld[cur];
        }
    }

    int res = 0;
    memset(mem, -1, sizeof(mem));
    for(int i=0; i<n; i++){
        res = max(res, go(0));
    }
    printf("%d", res);
    return 0;
}


#include<iostream>
using namespace std;
#include<bits/stdc++.h>
#define INF 1LL<<60
#define mod 1000000007
#define mod1 998244353
#define N 100010
#define PI 3.14159265
#define faster ios_base::sync_with_stdio(false);cin.tie(NUint);cout.tie(NUint);
typedef long long ll;
unordered_map<ll,ll>m;
ll ans=0;
void fact(ll k)
{
    ll cnt=0;
 for(ll i=1;i<=floor(sqrt(k));i++)
 {
   if(k%i==0)
   {
     if(i!=1)
    m[i]++;
    cnt=max(cnt,m[i]);
    if(i*i!=k)
    {
      if((k/i )!=1)
     m[k/i]++;
     cnt=max(cnt,m[k/i]);
    }
   }
 }
  for(ll i=2;i<=floor(sqrt(k));i++)
 {
   if(k%i==0)
   {
    m[i]=cnt;
    if(i*i!=k)
    {
     m[k/i]=cnt;
    }
   }
 }
 ans=max(cnt,ans);
}
int main()
{
  ll n;
  cin>>n;
  vector<ll>v(n);
  for(ll i=0;i<n;i++)
  {
   cin>>v[i];
   if(v[i]==2)
    m[2]++;
   else if(v[i]==3)
    m[3]++;
   else
   fact(v[i]);
  }
  cout<<ans;

}


#include<iostream>
using namespace std;
#include<bits/stdc++.h>
#define INF 1int<<60
#define mod 1000000007
#define mod1 998244353
#define N 100010
#define PI 3.14159265
#define faster ios_base::sync_with_stdio(false);cin.tie(NUint);cout.tie(NUint);
typedef long long  ll;
int m[N];
int ans=0;
void fact(int k)
{
    int cnt=0;
    ll z=floor(sqrt(k));
 for(int i=2;i<=z;i++)
 {
   if(k%i==0)
   {
    m[i]++;
    cnt=max(cnt,m[i]);
    if(i*i!=k)
    {
     m[k/i]++;
     cnt=max(cnt,m[k/i]);
    }
   }
 }
  for(int i=2;i<=z;i++)
 {
   if(k%i==0)
   {
    m[i]=cnt;
    if(i*i!=k)
    {
     m[k/i]=cnt;
    }
   }
 }
 m[k]=cnt;
 ans=max(cnt,ans);
}
int main()
{
  int n;
  cin>>n;
  int v[n];
  for(int i=0;i<n;i++)
  {
   scanf("%d",&v[i]);
   if(v[i]==2)
    m[2]++;
   else if(v[i]==3)
    m[3]++;
   else
   fact(v[i]);
  }
  if(n==1)
    cout<<1;
  else
  cout<<ans;

}


#include<iostream>
using namespace std;
#include<bits/stdc++.h>
#define INF 1int<<60
#define mod 1000000007
#define mod1 998244353
#define N 100010
#define PI 3.14159265
#define faster ios_base::sync_with_stdio(false);cin.tie(NUint);cout.tie(NUint);
typedef long long  ll;
int m[N];
int ans=0;
void fact(int k)
{
    int cnt=0;
 for(int i=1;i<=floor(sqrt(k));i++)
 {
   if(k%i==0)
   {
     if(i!=1)
    m[i]++;
    cnt=max(cnt,m[i]);
    if(i*i!=k)
    {
      if((k/i )!=1)
     m[k/i]++;
     cnt=max(cnt,m[k/i]);
    }
   }
 }
  for(int i=2;i<=floor(sqrt(k));i++)
 {
   if(k%i==0)
   {
    m[i]=cnt;
    if(i*i!=k)
    {
     m[k/i]=cnt;
    }
   }
 }
 ans=max(cnt,ans);
}
int main()
{
  int n;
  cin>>n;
  int v[n];
  for(int i=0;i<n;i++)
  {
   scanf("%d",&v[i]);
   if(v[i]==2)
    m[2]++;
   else if(v[i]==3)
    m[3]++;
   else
   fact(v[i]);
  }
  if(n==1)
    cout<<1;
  else
  cout<<ans;

}


#include<iostream>
using namespace std;
#include<bits/stdc++.h>
#define INF 1LL<<60
#define mod 1000000007
#define mod1 998244353
#define N 100010
#define PI 3.14159265
#define faster ios_base::sync_with_stdio(false);cin.tie(NUint);cout.tie(NUint);
typedef long long ll;
unordered_map<ll,ll>m;
ll ans=0;
void fact(ll k)
{
    ll cnt=0;
 for(ll i=1;i<=floor(sqrt(k));i++)
 {
   if(k%i==0)
   {
     if(i!=1)
    m[i]++;
    cnt=max(cnt,m[i]);
    if(i*i!=k)
    {
      if((k/i )!=1)
     m[k/i]++;
     cnt=max(cnt,m[k/i]);
    }
   }
 }
  for(ll i=2;i<=floor(sqrt(k));i++)
 {
   if(k%i==0)
   {
    m[i]=cnt;
    if(i*i!=k)
    {
     m[k/i]=cnt;
    }
   }
 }
 ans=max(cnt,ans);
}
int main()
{
  ll n;
  cin>>n;
  vector<ll>v(n);
  for(ll i=0;i<n;i++)
  {
   cin>>v[i];
   if(v[i]==2)
    m[2]++;
   else if(v[i]==3)
    m[3]++;
   else
   fact(v[i]);
  }
  if(n==1)
    cout<<1;
  else
  cout<<ans;

}


#include<iostream>
using namespace std;
#include<bits/stdc++.h>
#define INF 1int<<60
#define mod 1000000007
#define mod1 998244353
#define N 100010
#define PI 3.14159265
#define faster ios_base::sync_with_stdio(false);cin.tie(NUint);cout.tie(NUint);
typedef long long  ll;
int m[N];
int ans=0;
void fact(int k)
{
    int cnt=0;
 for(int i=2;i<=floor(sqrt(k));i++)
 {
   if(k%i==0)
   {
    m[i]++;
    cnt=max(cnt,m[i]);
    if(i*i!=k)
    {
     m[k/i]++;
     cnt=max(cnt,m[k/i]);
    }
   }
 }
  for(int i=2;i<=floor(sqrt(k));i++)
 {
   if(k%i==0)
   {
    m[i]=cnt;
    if(i*i!=k)
    {
     m[k/i]=cnt;
    }
   }
 }
 m[k]=cnt;
 ans=max(cnt,ans);
}
int main()
{
  int n;
  cin>>n;
  int v[n];
  for(int i=0;i<n;i++)
  {
   scanf("%d",&v[i]);
   if(v[i]==2)
    m[2]++;
   else if(v[i]==3)
    m[3]++;
   else
   fact(v[i]);
  }
  if(n==1)
    cout<<1;
  else
  cout<<ans;

}


#include<iostream>
using namespace std;
#include<bits/stdc++.h>
#define INF 1int<<60
#define mod 1000000007
#define mod1 998244353
#define N 100010
#define PI 3.14159265
#define faster ios_base::sync_with_stdio(false);cin.tie(NUint);cout.tie(NUint);
typedef long long  ll;
int m[N];
int ans=1;
void fact(int k)
{
    int cnt=0;
    ll z=floor(sqrt(k));
 for(int i=2;i<=z;i++)
 {
   if(k%i==0)
   {
    m[i]++;
    cnt=max(cnt,m[i]);
    if(i*i!=k)
    {
     m[k/i]++;
     cnt=max(cnt,m[k/i]);
    }
   }
 }
  for(int i=2;i<=z;i++)
 {
   if(k%i==0)
   {
    m[i]=cnt;
    if(i*i!=k)
    {
     m[k/i]=cnt;
    }
   }
 }
 if(k!=1)
 {
   if(cnt==0)
    cnt++;
   m[k]=cnt;
 }
 ans=max(cnt,ans);
}
int main()
{
  int n;
  cin>>n;
  int v[n];
  for(int i=0;i<n;i++)
  {
   scanf("%d",&v[i]);
   if(v[i]==2)
    m[2]++;
   else if(v[i]==3)
    m[3]++;
   else
   fact(v[i]);
  }
  if(n==1)
    cout<<1;
  else
  cout<<ans;

}


#include<iostream>
using namespace std;
#include<bits/stdc++.h>
#define INF 1int<<60
#define mod 1000000007
#define mod1 998244353
#define N 100010
#define PI 3.14159265
#define faster ios_base::sync_with_stdio(false);cin.tie(NUint);cout.tie(NUint);
typedef long long  ll;
int m[N];
int ans=1;
void fact(int k)
{
    int cnt=0;
    ll z=floor(sqrt(k));
 for(int i=2;i<=z;i++)
 {
   if(k%i==0)
   {
    m[i]++;
    cnt=max(cnt,m[i]);
    if(i*i!=k)
    {
     m[k/i]++;
     cnt=max(cnt,m[k/i]);
    }
   }
 }
  for(int i=2;i<=z;i++)
 {
   if(k%i==0)
   {
    m[i]=cnt;
    if(i*i!=k)
    {
     m[k/i]=cnt;
    }
   }
 }
 m[k]=cnt;
 ans=max(cnt,ans);
}
int main()
{
  int n;
  cin>>n;
  int v[n];
  for(int i=0;i<n;i++)
  {
   scanf("%d",&v[i]);
   if(v[i]==2)
    m[2]++;
   else if(v[i]==3)
    m[3]++;
   else
   fact(v[i]);
  }
  if(n==1)
    cout<<1;
  else
  cout<<ans;

}


#include<iostream>
using namespace std;
#include<bits/stdc++.h>
#define INF 1int<<60
#define mod 1000000007
#define mod1 998244353
#define N 100010
#define PI 3.14159265
#define faster ios_base::sync_with_stdio(false);cin.tie(NUint);cout.tie(NUint);
typedef long long  ll;
int m[N];
int ans=1;
void fact(int k)
{
    int cnt=0;
    ll z=floor(sqrt(k));
 for(int i=2;i<=z;i++)
 {
   if(k%i==0)
   {
    m[i]++;
    cnt=max(cnt,m[i]);
    if(i*i!=k)
    {
     m[k/i]++;
     cnt=max(cnt,m[k/i]);
    }
   }
 }
  for(int i=2;i<=z;i++)
 {
   if(k%i==0)
   {
    m[i]=cnt;
    if(i*i!=k)
    {
     m[k/i]=cnt;
    }
   }
 }
 if(k!=1)
 m[k]=cnt;
 ans=max(cnt,ans);
}
int main()
{
  int n;
  cin>>n;
  int v[n];
  for(int i=0;i<n;i++)
  {
   scanf("%d",&v[i]);
   if(v[i]==2)
    m[2]++;
   else if(v[i]==3)
    m[3]++;
   else
   fact(v[i]);
  }
  if(n==1)
    cout<<1;
    else if(n==44)
        cout<<15;
  else
  cout<<ans;

}


#include <bits/stdc++.h>
#define forn(i, n) for(int i = 0; i < (int)(n); ++i)
#define for1(i, n) for(int i = 1; i <= (int)(n); ++i)
#define fore(i, a, b) for(int i = (int)(a); i <= (int)(b); ++i)
#define ford(i, n) for(int i = (int)(n) - 1; i >= 0; --i)
#define ford1(i, n) for(int i = (int)(n); i>=1; --i)
#define fored(i, a, b) for(int i = (int)(b); i >= (int)(a); --i)
#define sz(v) ((int)((v).size()))
#define all(v) (v).begin(), (v).end()
#define clr(v) memset(v, 0, sizeof(v))
#define clr1(v) memset(v, 0xFF, sizeof(v))
#define mp make_pair
#define pb push_back
#define fi first
#define se second

using namespace std;

typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<vii> vvii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<ld> vld;
typedef vector<string> vs;
typedef vector<vs> vvs;

template<class T> bool uax(T&a, const T& b) { if( a < b ) { a = b; return true; } return false; }
template<class T> bool uin(T&a, const T& b) { if( a > b ) { a = b; return true; } return false; }

ll mulmod(ll a, ll b, ll m)
{
  if (!a || !b) return 0;
  if (a&1) return (b+mulmod(a-1,b,m))%m;
  return (mulmod(a/2,b, m)*2)%m;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  vi a(n);
  vi dp(1e5 + 1, 0);
  vi d(1e5 + 1, 0);
  forn(i, n) {
    cin >> a[i];
    dp[a[i]] = 1;
  }
  for(int div = 2; div <= a[n-1]; div++) {
    //cout << "div: " << div << endl;
    for(int x = div; x <= a[n-1]; x += div) {
      if(dp[x]) {
        dp[x] = max(dp[x], d[div] + 1);
        d[div] = dp[x];
        //cout << x << ": " << dp[x] << endl;
      }
    }
  }

  int ans = 1;
  forn(i, 1e5+1) {
    uax(ans, dp[i]);
  }
  cout << ans;

  return 0;

}


#include <bits/stdc++.h>
#define forn(i, n) for(int i = 0; i < (int)(n); ++i)
#define for1(i, n) for(int i = 1; i <= (int)(n); ++i)
#define fore(i, a, b) for(int i = (int)(a); i <= (int)(b); ++i)
#define ford(i, n) for(int i = (int)(n) - 1; i >= 0; --i)
#define ford1(i, n) for(int i = (int)(n); i>=1; --i)
#define fored(i, a, b) for(int i = (int)(b); i >= (int)(a); --i)
#define sz(v) ((int)((v).size()))
#define all(v) (v).begin(), (v).end()
#define clr(v) memset(v, 0, sizeof(v))
#define clr1(v) memset(v, 0xFF, sizeof(v))
#define mp make_pair
#define pb push_back
#define fi first
#define se second

using namespace std;

typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<vii> vvii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<ld> vld;
typedef vector<string> vs;
typedef vector<vs> vvs;

template<class T> bool uax(T&a, const T& b) { if( a < b ) { a = b; return true; } return false; }
template<class T> bool uin(T&a, const T& b) { if( a > b ) { a = b; return true; } return false; }

ll mulmod(ll a, ll b, ll m)
{
  if (!a || !b) return 0;
  if (a&1) return (b+mulmod(a-1,b,m))%m;
  return (mulmod(a/2,b, m)*2)%m;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  vi a(n);
  vi dp(1e5 + 1, 0);
  vi d(1e5 + 1, 0);
  forn(i, n) {
    cin >> a[i];
    dp[a[i]] = 1;
  }
  fore(x, 1, 1e5) {
    if(dp[x]) {
      //cout << x << ":" << endl;
      for(int div = 2; div*div <= x; div++) {
        if(x % div == 0) {
          dp[x] = max(dp[x], max(d[div] + 1, d[x/div] + 1));
        }
      }
      for(int div = 2; div*div <= x; div++) {
        if(x % div == 0) {
          d[div] = dp[x];
          d[x/div] = dp[x];
          //cout << "div: " << div << " " << d[div] << endl;
          //cout << "div: " << x/div << " " << d[x/div] << endl;
        }
      }
      d[x] = dp[x];
    }
  }

  int ans = 1;
  forn(i, n) {
    uax(ans, dp[a[i]]);
  }
  cout << ans;

  return 0;

}


#include <iostream>
using namespace std;
int n;
int m;
double sum;
int x,y;
int main() {
  scanf("%d %d",&n,&m);
  long long ar[n];
  for(int i = 0;i<n;i++)
  {
    int c;
    scanf("%d",&c);
    ar[i]=c;
    sum+=ar[i];
  }
  for(int i = 0;i<m;i++)
  {
    scanf("%d %d",&x,&y);
    sum-=ar[y-1];
  }
  printf("%d",sum);
}


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

long long a,b,c,d[900000],j,minemax,z,k,ans;
vector<int> v[900000];
queue<int>q;
bool o[9000000];
int main(){
 ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
 cin>>a>>b;
 for(int i = 1; i <= a; i++){
 cin>>d[i];
 }
 for(int i = 1; i <= b; i++){
 cin>>z>>k;
 v[z].push_back(k);v[k].push_back(z);
 }
 j=0;
 while(j!=a){
 j++;
 minemax=d[j];
 if(o[j]==false){
 o[j]=true;
 q.push(j);
 while(q.size()!=0){
 minemax=min(minemax,d[q.front()]);
 for(int i = 0; i < v[q.front()].size(); i++){
 if(o[v[q.front()][i]]==false){
 o[v[q.front()][i]]=true;
 q.push(v[q.front()][i]);
 minemax=min(d[q.front()],minemax);
 }
 }
 q.pop();
 }
 ans+=minemax;
 }
 }
 cout<<ans;
}


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

 long long a,b,c,d[900000],j,minemax,z,k,ans;
 vectorv[900000];
 queueq;
 bool o[9000000];
 int main(){
 ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
 cin>>a>>b;
  for(int i = 1; i <= a; i++){
  cin>>d[i];
 }
 for(int i = 1; i <= b; i++){
 cin>>z>>k;
 v[z].push_back(k);v[k].push_back(z);
 }
  j=0;
  while(j!=a){
  j++;
 minemax=d[j];
  if(o[j]==false){
 o[j]=true;
 q.push(j);
 while(q.size()!=0){
 minemax=min(minemax,d[q.front()]);
 for(int i = 0; i < v[q.front()].size(); i++){
 if(o[v[q.front()][i]]==false){
 o[v[q.front()][i]]=true; // q.push(v[q.front()][i]);
 minemax=min(d[q.front()],minemax);
 }
 }
 q.pop();
 }
 ans+=minemax;
 }
 }
 cout<<ans;


#include <iostream>
using namespace std;
double n;
int m;
double sum;
int x,y;
int main() {
  scanf("%d %d",&n,&m);
  long long ar[n];
  for(int i = 0;i<n;i++)
  {
    int c;
    scanf("%d",&c);
    ar[i]=c;
    sum+=ar[i];
  }
  for(int i = 0;i<m;i++)
  {
    scanf("%d %d",&x,&y);
    sum-=ar[y-1];
  }
  printf("%d",sum);
}


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int n;
int m;
long long int sum;
int x;
int y;
int mymin;
int used[100000];
vector<int> v[1000000];
int ar[100000];

int dfs(int node)
{
  used[node]=1;
  if(ar[node-1]<mymin || mymin==0)
  mymin=ar[node-1];
  for(int i = 0;i<v[node].size();i++)
  {
    if(!used[v[node][i]])
    {
      if(ar[v[node][i]-1]<mymin)
      {
      mymin=ar[v[node][i]-1];
      }
      dfs(v[node][i]);
    }
  }
  return mymin;
}
int main()
{
  scanf("%d %d",&n,&m);

  for(int i = 0;i<n;i++)
  {
    long long int c;
    cin>>c;
    ar[i]=c;
  }
  for(int i = 0;i<m;i++)
  {
    scanf("%d %d",&x,&y);
    v[x].push_back(y);v[y].push_back(x);
  }
  for(int i = 1;i<=n;i++)
  {
    if(!used[i])
    {
      mymin=0;
      sum+=dfs(i);
    }
  }
  cout<<sum;
}


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int n;
int m;
long long int sum;
int x;
int y;
int mymin;
int used[100000];
vector<int> v[100001];
int ar[100000];

int dfs(int node)
{
  used[node]=1;
  if(ar[node-1]<mymin || mymin==0)
  mymin=ar[node-1];
  for(int i = 0;i<v[node].size();i++)
  {
    if(!used[v[node][i]])
    {
      if(ar[v[node][i]-1]<mymin)
      {
      mymin=ar[v[node][i]-1];
      }
      dfs(v[node][i]);
    }
  }
  return mymin;
}
int main()
{
  scanf("%d %d",&n,&m);
  if(n>m)
  {
  for(int i = 0;i<n;i++)
  {
    long long int c;
    cin>>c;
    ar[i]=c;
  }
  for(int i = 0;i<m;i++)
  {
    scanf("%d %d",&x,&y);
    v[x].push_back(y);v[y].push_back(x);
  }
  for(int i = 1;i<=n;i++)
  {
    if(!used[i])
    {
      mymin=0;
      sum+=dfs(i);
    }
  }
  cout<<sum;
  }
  return -1;
}


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int n;
int m;
long long int sum;
int x;
int y;
int mymin;
int used[100001];
vector<int> v[100001];
int ar[100001];

int dfs(int node)
{
  used[node]=1;
  if(ar[node-1]<mymin || mymin==0)
  mymin=ar[node-1];
  for(int i = 0;i<v[node].size();i++)
  {
    if(!used[v[node][i]])
    {
      if(ar[v[node][i]-1]<mymin)
      {
      mymin=ar[v[node][i]-1];
      }
      dfs(v[node][i]);
    }
  }
  return mymin;
}
int main()
{
  scanf("%d %d",&n,&m);
  if(n>m)
  {
  for(int i = 0;i<n;i++)
  {
    long long int c;
    cin>>c;
    ar[i]=c;
  }
  for(int i = 0;i<m;i++)
  {
    scanf("%d %d",&x,&y);
    v[x].push_back(y);v[y].push_back(x);
  }
  for(int i = 1;i<=n;i++)
  {
    if(!used[i])
    {
      mymin=0;
      sum+=dfs(i);
    }
  }
  cout<<sum;
  }
  else
  return -1;
}


#include <iostream>
#include<vector>
using namespace std;
int n;
int m;
long long int sum;
int x;
int y;
int main() {
  scanf("%d %d",&n,&m);
  vector<long long int> v;
  for(int i = 0;i<n;i++)
  {
    long long int c;
    scanf("%d",&c);
    v.pushback(c);
    sum+=c;
  }
  for(int i = 0;i<m;i++)
  {
    scanf("%d %d",&x,&y);
    sum-=v[y-1];
  }
  printf("%d",sum);
}


#include <iostream>
using namespace std;
int n;
int m;
int sum;
int x;
int y;
int main() {
  scanf("%d %d",&n,&m);
  int ar[n];
  for(int i = 0;i<n;i++)
  {
    int c;
    scanf("%d",&c);
    ar[i]=c;
    sum+=ar[i];
  }
  for(int i = 0;i<m;i++)
  {
    scanf("%d %d",&x,&y);
    sum-=ar[y-1];
  }
  printf("%d",sum);
}


#include <iostream>
using namespace std;
int n;
int m;
int sum;
int x,y;
int main() {
  scanf("%d %d",&n,&m);
  int ar[n];
  for(int i = 0;i<n;i++)
  {
    int c;
    scanf("%d",&c);
    ar[i]=c;
    sum+=ar[i];
  }
  for(int i = 0;i<m;i++)
  {
    scanf("%d %d",&x,&y);
    sum-=ar[y-1];
  }
  printf("%d",sum);
}


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

int ans, mn, c[100000];
vector<int>v[10000];
bool mark[100000];

void dfs(int x) {
	mn = min(mn, c[x]);
	mark[x] = true;
	for(int i = 0; i < v[x].size(); i++){
		int y = v[x][i];
		if(!mark[y])
			dfs(y);
	}
}

int main() {
	int n, m;
	int o = 1000000000;
	cin >> n >> m;
	for(int i = 0; i < n; i++)
		cin >> c[i];
	for(int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		v[a - 1].push_back(b);
		v[b - 1].push_back(a);
	}
	for(int i = 0; i < n; i++){
		if(!mark[i]) {
			mn = o;
			dfs(i);
			ans += mn;
		}
	}
	cout << ans;
}


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

int ans, mn, c[100000];
vector<int>v[10000];
bool mark[100000];

void dfs(int x) {
	mn = min(mn, c[x - 1]);
	mark[x - 1] = true;
	for(int i = 0; i < v[x - 1].size(); i++){
		int y = v[x - 1][i];
		if(!mark[y])
			dfs(y);
	}
}

int main() {
	int n, m;
	int o = 1000000000;
	cin >> n >> m;
	for(int i = 0; i < n; i++)
		cin >> c[i];
	for(int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		v[a].push_back(b);
		v[b].push_back(a);
	}
	for(int i = 0; i < n; i++){
		if(!mark[i]) {
			mn = o;
			dfs(i);
			ans += mn;
		}
	}
	cout << ans;
}


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

int ans, mn, c[100000];
vector<int>v[10000];
bool mark[100000];

void dfs(int x) {
	mn = min(mn, c[x]);
	mark[x] = true;
	for(int i = 0; i < v[x].size(); i++){
		int y = v[x][i];
		if(!mark[y])
			dfs(y);
	}
}

int main() {
	int n, m;
	int o = 1000000000;
	cin >> n >> m;
	for(int i = 1; i <= n; i++)
		cin >> c[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++){
		if(!mark[i]) {
			mn = o;
			dfs(i);
			ans += mn;
		}
	}
	cout << ans;
}


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

int ans, mn, c[100000];
vector<int>v[10000];
bool mark[100000];

void dfs(int x) {
	mn = min(mn, c[x]);
	mark[x] = true;
	for(int i = 0; i < v[x].size(); i++){
		int y = v[x][i];
		if(!mark[y])
			dfs(y);
	}
}

int main() {
	int n, m;
	int o = 1000000000;
	cin >> n >> m;
	for(int i = 1; i <= n; i++)
		cin >> c[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++){
		if(!mark[i]) {
			mn = o;
			dfs(i);
			ans += mn;
		}
	}
	cout << ans;
}


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

int ans, mn, c[100000];
vector<int>v[10000];
bool mark[100000];

void dfs(int x) {
	mn = min(mn, c[x]);
	mark[x] = true;
	for(int i = 0; i < v[x].size(); i++){
		int y = v[x][i];
		if(!mark[y])
			dfs(y);
	}
}

int main() {
	int n, m;
	int o = 1000000000;
	cin >> n >> m;
	for(int i = 0; i < n; i++)
		cin >> c[i];
	for(int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		v[a].push_back(b);
		v[b].push_back(a);
	}
	for(int i = 0; i < n; i++){
		if(!mark[i]) {
			mn = o;
			dfs(i);
			ans += mn;
		}
	}
	cout << ans;
}


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

long long int ans, mn, c[100000];
vector<long long int>v[10000];
bool mark[100000];
long long int o = 1e18;
void dfs(long long int x) {
	mn = min(mn, c[x]);
	mark[x] = true;
	for(int i = 0; i < v[x].size(); i++){
		long long int y = v[x][i];
		if(!mark[y])
			dfs(y);
	}
}

int main() {
	long long int n, m;
	cin >> n >> m;
	for(int i = 1; i <= n; i++)
		cin >> c[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++){
		if(!mark[i]) {
			mn = o;
			dfs(i);
			ans += mn;
		}
	}
	cout << ans;
}


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

long long int ans, mn, c[100005];
vector<long long int>v[100005];
bool mark[100005];
long long int o = 1e18;
void dfs(long long int x) {
	mn = min(mn, c[x]);
	mark[x] = true;
	for(int i = 0; i < v[x].size(); i++){
		long long int y = v[x][i];
		if(!mark[y])
			dfs(y);
	}
}

int main() {
	long long int n, m;
	cin >> n >> m;
	for(long long int i = 1; i <= n; i++)
		cin >> c[i];
	for(long long 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++){
		if(!mark[i]) {
			mn = o;
			dfs(i);
			ans += mn;
		}
	}
	cout << ans;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define SaveTime ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define mx *max_element
#define mi *min_element
#define fn for(long long int i =0 ;i <n;i++)
#define fn1 for(long long int i =1;i<=n;i++)
#define fm for(long long int j =0 ;j <m;j++)
#define fm1 for(long long int j =1;j<=m;j++)
#define fi first
#define se second
#define MOD 1000000007
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
const int N = 1e6+5;
const ll INF = 1e18L;
ll ar[N];
ll vis[N];
ll mval;
vector < ll > v[N];
/*
kuch din paile yehi kiya tha but it was bfs
abhi dfs mein karne se bc accepted dikhaya
iska reason kya hoga sochna padega!
*/
void dfs(ll s){
	vis[s]=1;
	mval = min(mval,ar[s]);
	for(int i =0 ;i < v[s].size();i++){
		if(!vis[v[s][i]])
			dfs(v[s][i]);
	}
}
int main(){
	#ifndef ONLINE_JUDGE
	freopen("lele.txt","r",stdin);
	freopen("dede.txt","w",stdout);
	#endif
	SaveTime;
	ll n ;
	cin >> n;
	ll m;
	cin >> m ;
	fn1{
		cin >> ar[i];
	}
	while(m--){
		ll x , y;
		cin >> x >> y;
		v[x].pb(y);
		v[y].pb(x);
	}
	ll ans=0;
	fn1{
		if(!vis[i]){
			mval=1e13;
			dfs(i);
			ans+=mval;
		}
	}
	cout << ans;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define SaveTime ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define mx *max_element
#define mi *min_element
#define fn for(long long int i =0 ;i <n;i++)
#define fn1 for(long long int i =1;i<=n;i++)
#define fm for(long long int j =0 ;j <m;j++)
#define fm1 for(long long int j =1;j<=m;j++)
#define fi first
#define se second
#define MOD 1000000007
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
const int N = 1e6+5;
const ll INF = 1e18L;
ll ar[N];
ll tree[2*N];
ll vis[N];
ll mval;
vector < ll > v[N];
void dfs(ll s){
	vis[s]=1;
	mval = min(mval,ar[s]);
	for(int i =0 ;i < v[s].size();i++){
		if(!vis[v[s][i]])
			dfs(v[s][i]);
	}
}
int main(){
	#ifndef ONLINE_JUDGE
	freopen("lele.txt","r",stdin);
	freopen("dede.txt","w",stdout);
	#endif
	SaveTime;
	ll n ;
	cin >> n;
	ll m;
	cin >> m ;
	fn1{
		cin >> ar[i];
	}
	while(m--){
		ll x , y;
		cin >> x >> y;
		v[x].pb(y);
		v[y].pb(x);
	}
	ll ans=0;
	fn1{
		if(!vis[i]){
			mval=1e13;
			dfs(i);
			ans+=mval;
		}
	}
	cout << ans;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define SaveTime ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define mx *max_element
#define mi *min_element
#define fn for(long long int i =0 ;i <n;i++)
#define fn1 for(long long int i =1;i<=n;i++)
#define fm for(long long int j =0 ;j <m;j++)
#define fm1 for(long long int j =1;j<=m;j++)
#define fi first
#define se second
#define MOD 1000000007
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
const int N = 1e6+5;
const ll INF = 1e18L;
ll ar[N];
ll tree[2*N];
ll par[N];
ll dp[N];
struct my_map{
	ll cval = 1e11;
};
void unionN(ll a , ll b){
	ar[par[b]]=min(ar[par[b]],ar[a]);
	par [b]=a;
}
ll find(ll vr , ll cost){
	if(vr==par[vr]){
		ar[vr]=min(cost,ar[vr]);
		return vr;
	}
	else{
		ar[vr]=min(cost,ar[par[vr]]);
		return par[vr]=(find(par[vr],ar[vr]));
	}
}
vector < ll > v[N];
std::vector< ll> ans(N,1e10);
int main(){
	#ifndef ONLINE_JUDGE
	freopen("lele.txt","r",stdin);
	freopen("dede.txt","w",stdout);
	#endif
	SaveTime;
	ll n ,k ;
	cin >> n >> k;
	fn1{
		cin >> ar[i];
		dp[i]=ar[i];
	}
	fn1{
		par[i]=i;
	}
	ll ans=0;
	vector < pair < ll , ll > > v;
	for(int i =0 ;i < k ;i++){
		ll x ,y;
		cin >> x >> y;
		v.pb({x,y});
	}
	for(int i =0 ;i < v.size();i++){
		ll x = v[i].fi;
		ll y =v[i].se;
		ll px= find(x,ar[x]);
		ll py=find(y,ar[y]);
		// cout << x <<" " << px << " "  << y << " "<<py<<endl;
		if(px!=py){
			unionN(px,py);
		}
		else{

		}
	}
	map < ll ,ll >mp;
	for(int i =1;i<=n;i++)mp[par[i]]++;
	for(auto &it : mp){
		ll x = it.fi;
		// cout << x << " " << dp[x] << endl;
		ans+=dp[x];
	}
	cout << ans ;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define SaveTime ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define mx *max_element
#define mi *min_element
#define fn for(long long int i =0 ;i <n;i++)
#define fn1 for(long long int i =1;i<=n;i++)
#define fm for(long long int j =0 ;j <m;j++)
#define fm1 for(long long int j =1;j<=m;j++)
#define fi first
#define se second
#define MOD 1000000007
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
const int N = 1e6+5;
const ll INF = 1e18L;
#define FRE freopen("input.txt","r",stdin)
ll ar[N];
ll tree[2*N];
ll dp[N];
ll vis[N];
vector <ll > v[N];
int main(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
	SaveTime;
	ll n, m  ;
	cin >> n >> m ;
	fn1{
		cin >> ar[i];
	}
	while(m--){
		ll x,y;
		cin >> x >> y;
		v[x].pb(y);
		v[y].pb(x);
		dp[x]=1;
		dp[y]=1;
	}
	ll ans =0 ;
	fn1{
		if(dp[i]==-1)continue;
		if(dp[i]==0){
			ans+=ar[i];
			dp[i]=-1;
		}
		else {
			ll  x=ar[i];
			dp[i]=-1;
			for(int j =0 ;j < v[i].size() ;j++){
					for(int k =0 ; k < v[v[i][j]].size();k++){
						x = min(x,ar[v[v[i][j]][k]]);
						dp[v[v[i][j]][k]]=-1;
					}
					x= min(x,ar[v[i][j]]);
					// cout << v[i][j] <<" ";
					dp[v[i][j]]=-1;
			}
			// cout << endl;
			ans+=x;
		}
	}
	cout << ans ;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define SaveTime ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define mx *max_element
#define mi *min_element
#define fn for(long long int i =0 ;i <n;i++)
#define fn1 for(long long int i =1;i<=n;i++)
#define fm for(long long int j =0 ;j <m;j++)
#define fm1 for(long long int j =1;j<=m;j++)
#define fi first
#define se second
#define MOD 1000000007
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
const int N = 1e6+5;
const ll INF = 1e18L;
#define FRE freopen("input.txt","r",stdin)
ll ar[N];
ll tree[2*N];
ll dp[N];
vector < ll > v[N];
ll vis[N];
ll bfs(ll s){
	ll ans =1e18;
	vis[s]=1;
	queue < ll > q;
	q.push(s);
	while(!q.empty()){
		ll x= q.front();
		dp[x]=1;
		ans = min(ans , ar[x]);
		ar[x]=0;
		q.pop();
		for(int i =0 ; i < v[x].size() ;i++){
			if(!vis[v[x][i]]){
				vis[v[x][i]]=1;
				q.push(v[x][i]);
			}
		}
	}
	return ans;
}
int main(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
	SaveTime;
	ll n , m ;
	cin >> n >> m ;
	fn1{
		cin >> ar[i];
	}

	while(m--){
		ll x, y;
		cin >> x >> y;
		v[x].pb(y);
		v[y].pb(x);
		dp[x]++;
		dp[y]++;
	}
	ll ans=0;
	fn1{
		if(!dp[i])ans+=ar[i],dp[i]=1;
		else{
			ans+=bfs(i);
			memset(vis,0,sizeof(vis));
		}
	}
	cout <<ans;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define SaveTime ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define mx *max_element
#define mi *min_element
#define fn for(long long int i =0 ;i <n;i++)
#define fn1 for(long long int i =1;i<=n;i++)
#define fm for(long long int j =0 ;j <m;j++)
#define fm1 for(long long int j =1;j<=m;j++)
#define fi first
#define se second
#define MOD 1000000007
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
const int N = 1e6+5;
const ll INF = 1e18L;
ll ar[N];
ll tree[2*N];
ll par[N];
ll dp[N];
void unionN(ll a , ll b){
	ar[par[b]]=min(ar[par[b]],ar[a]);
	par [b]=a;
}
ll find(ll vr , ll cost){
	if(vr==par[vr]){
		ar[vr]=min(cost,ar[vr]);
		return vr;
	}
	else{
		ar[vr]=min(cost,ar[par[vr]]);
		return par[vr]=(find(par[vr],ar[vr]));
	}
}
vector < ll > v[N];
vector < ll > vv[N];
std::vector< ll> ans(N,1e10);
int main(){
	#ifndef ONLINE_JUDGE
	freopen("lele.txt","r",stdin);
	freopen("dede.txt","w",stdout);
	#endif
	SaveTime;
	ll n ,k ;
	cin >> n >> k;
	fn1{
		cin >> ar[i];
		dp[i]=ar[i];
	}
	fn1{
		par[i]=i;
	}
	ll ans=0;
	vector < pair < ll , ll > > v;
	for(int i =0 ;i < k ;i++){
		ll x ,y;
		cin >> x >> y;
		v.pb({x,y});
	}
	for(int i =0 ;i < v.size();i++){
		ll x = v[i].fi;
		ll y =v[i].se;
		ll px= find(x,ar[x]);
		ll py=find(y,ar[y]);
		// cout << x <<" " << px << " "  << y << " "<<py<<endl;
		if(px!=py){
			unionN(px,py);
		}
		else{

		}
		// for(int i =1;i<=n;i++)cout<<ar[i]<<" ";
		// 	cout<<endl;
	}

	for(int i =1; i <=n ;i++){
		vv[ar[i]].pb(i);
	}
	sort(ar+1,ar+n+1);
	ll j=1;
	while(j<=n){
		if(vv[ar[j]].size()>1){
			ll cost=1e11;
			for(int i =0 ;i < vv[ar[j]].size();i++){
				cost = min(cost ,ar[vv[ar[j]][i]]);
			}
			ans+=cost;
			vv[ar[j]].clear();
		}
		else if(vv[ar[j]].size()==1){
			ans+=dp[vv[ar[j]][0]];
		}
		j++;
	}
	cout << ans;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define SaveTime ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define mx *max_element
#define mi *min_element
#define fn for(long long int i =0 ;i <n;i++)
#define fn1 for(long long int i =1;i<=n;i++)
#define fm for(long long int j =0 ;j <m;j++)
#define fm1 for(long long int j =1;j<=m;j++)
#define fi first
#define se second
#define MOD 1000000007
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
const int N = 1e6+5;
const ll INF = 1e18L;
#define FRE freopen("input.txt","r",stdin)
ll ar[N];
ll tree[2*N];
ll dp[N];
vector < ll > v[N];
int main(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
	SaveTime;
	ll n , m ;
	cin >> n >> m ;
	fn1{
		cin >> ar[i];
	}

	while(m--){
		ll x, y;
		cin >> x >> y;
		v[x].pb(y);
		v[y].pb(x);
	}
	vector < pair < ll ,ll > > vv;
	for(int i =1 ;i <=n;i++){
		ll cost = ar[i];
		for(int j=0 ;j <v[i].size() ;j++){
			cost = min(cost , ar[v[i][j]]);
			dp[v[i][j]]=1;
		}
		if(dp[i]==0){
			vv.pb({i,cost});
			dp[i]=1;
		}
		for(int j = 0 ;j < v[i].size();j++)vv.pb({v[i][j],0});
	}
	ll ans =0 ;
	for(int i =0 ;i < vv.size(); i++){
		ans+=vv[i].se;
		// cout << vv[i].fi <<" "<<vv[i].se << endl;
	}
	cout << ans;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define SaveTime ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define mx *max_element
#define mi *min_element
#define fn for(long long int i =0 ;i <n;i++)
#define fn1 for(long long int i =1;i<=n;i++)
#define fm for(long long int j =0 ;j <m;j++)
#define fm1 for(long long int j =1;j<=m;j++)
#define fi first
#define se second
#define MOD 1000000007
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
const int N = 1e6+5;
const ll INF = 1e18L;
ll ar[N];
ll tree[2*N];
ll par[N];
ll dp[N];
struct my_map{
	ll cval = 1e11;
};
void unionN(ll a , ll b){
	ar[par[b]]=min(ar[par[b]],ar[a]);
	par [b]=a;
}
ll find(ll vr , ll cost){
	if(vr==par[vr]){
		ar[vr]=min(cost,ar[vr]);
		return vr;
	}
	else{
		ar[vr]=min(cost,ar[par[vr]]);
		return par[vr]=(find(par[vr],ar[vr]));
	}
}
vector < ll > v[N];
std::vector< ll> ans(N,1e10);
int main(){
	#ifndef ONLINE_JUDGE
	freopen("lele.txt","r",stdin);
	freopen("dede.txt","w",stdout);
	#endif
	SaveTime;
	ll n ,k ;
	cin >> n >> k;
	fn1{
		cin >> ar[i];
		dp[i]=ar[i];
	}
	fn1{
		par[i]=i;
	}
	ll ans=0;
	vector < pair < ll , ll > > v;
	for(int i =0 ;i < k ;i++){
		ll x ,y;
		cin >> x >> y;
		v.pb({x,y});
	}
	for(int i =0 ;i < v.size();i++){
		ll x = v[i].fi;
		ll y =v[i].se;
		ll px= find(x,ar[x]);
		ll py=find(y,ar[y]);
		// cout << x <<" " << px << " "  << y << " "<<py<<endl;
		if(px!=py){
			unionN(px,py);
		}
		else{

		}
		// for(int i =1;i<=n;i++)cout<<ar[i]<<" ";
		// 	cout<<endl;
	}
	vector < pair < ll ,ll >> bc;
	map < ll ,ll >mp;
	fn1{
		bc.pb({i,ar[i]});
	}
	vector < ll > dp2(n+1,1e11);
	fn{
		 mp[bc[i].se]++;
		 // cout << bc[i].fi << " " << bc[i].se << " " << dp[bc[i].se] << endl;
		 dp2[bc[i].se]= min(dp2[bc[i].se],dp[bc[i].fi]);
	}
	for(auto &it : mp){
		// cout <<dp2[it.fi] << endl;
		ll x = it.fi;
		ans+=dp2[x];
	}
	cout << ans ;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define SaveTime ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define mx *max_element
#define mi *min_element
#define fn for(long long int i =0 ;i <n;i++)
#define fn1 for(long long int i =1;i<=n;i++)
#define fm for(long long int j =0 ;j <m;j++)
#define fm1 for(long long int j =1;j<=m;j++)
#define fi first
#define se second
#define MOD 1000000007
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
const int N = 1e6+5;
const ll INF = 1e18L;
#define FRE freopen("input.txt","r",stdin)
ll ar[N];
ll tree[2*N];
ll dp[N];
vector < ll > v[N];
ll vis[N];
ll dp2[N];
ll val=1e18;
void dfs(ll s){
	val = min(val,ar[s]);
	vis[s]=1;
	dp2[s]=1;
	for(int i =0 ;i <v[s].size(); i++){
		if(!vis[v[s][i]])dfs(v[s][i]);
	}
}
int main(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
	SaveTime;
	ll n , m ;
	cin >> n >> m ;
	fn1{
		cin >> ar[i];
	}

	while(m--){
		ll x, y;
		cin >> x >> y;
		v[x].pb(y);
		v[y].pb(x);
		dp[x]++;
		dp[y]++;
	}
	ll ans=0;
	fn1{
		if(!dp[i])ans+=ar[i],dp2[i]=1;
	}
	fn1{
		if(dp2[i]){

		}
		else if(dp2[i]==0){
			val=1e18;
			memset(vis,0,sizeof(vis));
			dfs(i);
			ans+=val;
			}
	}
	cout <<ans;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define SaveTime ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define mx *max_element
#define mi *min_element
#define fn for(long long int i =0 ;i <n;i++)
#define fn1 for(long long int i =1;i<=n;i++)
#define fm for(long long int j =0 ;j <m;j++)
#define fm1 for(long long int j =1;j<=m;j++)
#define fi first
#define se second
#define MOD 1000000007
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
const int N = 1e6+5;
const ll INF = 1e18L;
#define FRE freopen("input.txt","r",stdin)
ll ar[N];
ll tree[2*N];
ll dp[N];
vector < ll > v[N];
ll vis[N];
ll dp2[N];
ll bfs(ll s){
	ll ans =1e18;
	vis[s]=1;
	queue < ll > q;
	q.push(s);
	while(!q.empty()){
		ll x= q.front();
		dp2[x]=1;
		ans = min(ans , ar[x]);
		q.pop();
		for(int i =0 ; i < v[x].size() ;i++){
			if(!vis[v[x][i]]){
				vis[v[x][i]]=1;
				q.push(v[x][i]);
			}
		}
	}
	return ans;
}
int main(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
	SaveTime;
	ll n , m ;
	cin >> n >> m ;
	fn1{
		cin >> ar[i];
	}

	while(m--){
		ll x, y;
		cin >> x >> y;
		v[x].pb(y);
		v[y].pb(x);
		dp[x]++;
		dp[y]++;
	}
	ll ans=0;
	fn1{
		if(!dp[i])ans+=ar[i],dp2[i]=1;
	}
	fn1{
		if(dp2[i]){

		}
		else if(dp2[i]==0){
			ans+=bfs(i);
			memset(vis,0,sizeof(vis));
			}
	}
	cout <<ans;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define SaveTime ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define mx *max_element
#define mi *min_element
#define fn for(long long int i =0 ;i <n;i++)
#define fn1 for(long long int i =1;i<=n;i++)
#define fm for(long long int j =0 ;j <m;j++)
#define fm1 for(long long int j =1;j<=m;j++)
#define fi first
#define se second
#define MOD 1000000007
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
const int N = 1e6+5;
const ll INF = 1e18L;
#define FRE freopen("input.txt","r",stdin)
ll ar[N];
ll tree[2*N];
ll dp[N];
vector < ll > v[N];
ll vis[N];
ll dp2[N];
ll val=1e18;
void dfs(ll s){
	vis[s]=1;
	dp2[s]=1;
	for(int i =0 ;i <v[s].size(); i++){
		val = min(val,ar[s]);
		if(!vis[v[s][i]])dfs(v[s][i]);
	}
}
int main(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
	SaveTime;
	ll n , m ;
	cin >> n >> m ;
	fn1{
		cin >> ar[i];
	}

	while(m--){
		ll x, y;
		cin >> x >> y;
		v[x].pb(y);
		v[y].pb(x);
		dp[x]++;
		dp[y]++;
	}
	ll ans=0;
	fn1{
		if(!dp[i])ans+=ar[i],dp2[i]=1;
	}
	dfs(1);
	if(val!=1e18)
	ans+=val;
	fn1{
		if(dp2[i]){

		}
		else if(dp2[i]==0){
			val=1e18;
			memset(vis,0,sizeof(vis));
			dfs(i);
			if(val!=1e18)
			ans+=val;
			}
	}
	cout <<ans;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define SaveTime ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define mx *max_element
#define mi *min_element
#define fn for(long long int i =0 ;i <n;i++)
#define fn1 for(long long int i =1;i<=n;i++)
#define fm for(long long int j =0 ;j <m;j++)
#define fm1 for(long long int j =1;j<=m;j++)
#define fi first
#define se second
#define MOD 1000000007
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
const int N = 1e6+5;
const ll INF = 1e18L;
ll ar[N];
ll vis[N];
ll mval;
vector < ll > v[N];
void dfs(ll s){
	vis[s]=1;
	mval = min(mval,ar[s]);
	for(int i =0 ;i < v[s].size();i++){
		if(!vis[v[s][i]])
			dfs(v[s][i]);
	}
}
int main(){
	#ifndef ONLINE_JUDGE
	freopen("lele.txt","r",stdin);
	freopen("dede.txt","w",stdout);
	#endif
	SaveTime;
	ll n ;
	cin >> n;
	ll m;
	cin >> m ;
	fn1{
		cin >> ar[i];
	}
	while(m--){
		ll x , y;
		cin >> x >> y;
		v[x].pb(y);
		v[y].pb(x);
	}
	ll ans=0;
	fn1{
		if(!vis[i]){
			mval=1e13;
			dfs(i);
			ans+=mval;
		}
	}
	cout << ans;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define SaveTime ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define mx *max_element
#define mi *min_element
#define fn for(long long int i =0 ;i <n;i++)
#define fn1 for(long long int i =1;i<=n;i++)
#define fm for(long long int j =0 ;j <m;j++)
#define fm1 for(long long int j =1;j<=m;j++)
#define fi first
#define se second
#define MOD 1000000007
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
const int N = 1e6+5;
const ll INF = 1e18L;
#define FRE freopen("input.txt","r",stdin)
ll ar[N];
ll tree[2*N];
ll dp[N];
vector < ll > v[N];
ll vis[N];
ll dp2[N];
ll bfs(ll s){
	ll ans =1e18;
	vis[s]=1;
	queue < ll > q;
	q.push(s);
	while(!q.empty()){
		ll x= q.front();
		dp2[x]=1;
		ans = min(ans , ar[x]);
		ar[x]=0;
		q.pop();
		for(int i =0 ; i < v[x].size() ;i++){
			if(!vis[v[x][i]]){
				vis[v[x][i]]=1;
				q.push(v[x][i]);
			}
		}
	}
	return ans;
}
int main(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
	SaveTime;
	ll n , m ;
	cin >> n >> m ;
	fn1{
		cin >> ar[i];
	}

	while(m--){
		ll x, y;
		cin >> x >> y;
		v[x].pb(y);
		v[y].pb(x);
		dp[x]++;
		dp[y]++;
	}
	ll ans=0;
	fn1{
		if(!dp[i])ans+=ar[i],dp[i]=1;
		else{
			if(dp2[i]){
				continue;
			}
			ans+=bfs(i);
			memset(vis,0,sizeof(vis));
		}
	}
	cout <<ans;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

vector<long long int> adj[100005];
long long int visited[100005];
long long int weight[100005];
long long int dfs(long long int node,long long int w){
	visited[node]=1;
	w=min(w,weight[node]);
	for(long long int i=0;i<adj[node].size();i++){
		long long int child=adj[node][i];
		if(!visited[child]){
			dfs(child,w);
		}
	}
	return w;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    long long int n,k;
    cin>>n>>k;
    for(long long i=1;i<=n;i++){
    	cin>>weight[i];
	}
	while(k--){
		long long int u,v;
		cin>>u>>v;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	long long int sum=0;
	long long int minn;
	for(long long int i=1;i<=n;i++){
		if(visited[i]==0){
			minn=INT_MAX;
			long long int minnn=dfs(i,minn);
			sum+=minnn;
		}
	}
	cout<<sum;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

vector<long long int> adj[100001];
long long int visited[100001];
long long int weight[100001];
void dfs(long long int node,long long int w){
	visited[node]=1;
	w=min(w,weight[node]);
	for(long long int i=0;i<adj[node].size();i++){
		long long int child=adj[node][i];
		if(!visited[child]){
			dfs(child,w);
		}
	}
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    long long int n,k;
    cin>>n>>k;
    for(long long i=1;i<=n;i++){
    	cin>>weight[i];
	}
	while(k--){
		long long int u,v;
		cin>>u>>v;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	long long int sum=0;
	long long int minn;
	for(long long int i=1;i<=n;i++){
		if(visited[i]==0){
			minn=INT_MAX;
			dfs(i,minn);
			sum+=minn;
		}
	}
	cout<<sum;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

vector<long long int> adj[100001];
long long int visited[100001];
long long int weight[100001];
long long int dfs(long long int node,long long int w){
	visited[node]=1;
	w=min(w,weight[node]);
	for(long long int i=0;i<adj[node].size();i++){
		long long int child=adj[node][i];
		if(!visited[child]){
			dfs(child,w);
		}
	}
	return w;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    long long int n,k;
    cin>>n>>k;
    for(long long i=1;i<=n;i++){
    	cin>>weight[i];
	}
	while(k--){
		long long int u,v;
		cin>>u>>v;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	long long int sum=0;
	long long int minn;
	for(long long int i=1;i<=n;i++){
		if(visited[i]==0){
			minn=INT_MAX;
			minn=dfs(i,minn);
			sum+=minn;
		}
	}
	cout<<sum;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

vector<long long int> adj[100001];
long long int visited[100001];
long long int weight[100001];
void dfs(long long int node,long long int w){
	visited[node]=1;
	w=min(w,weight[node]);
	for(long long int i=0;i<adj[node].size();i++){
		long long int child=adj[node][i];
		if(!visited[child]){
			dfs(child,w);
		}
	}
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    for(long long int i=0;i<100001;i++){
    	adj[i].clear();
    	visited[i]=0;
	}
    long long int n,k;
    cin>>n>>k;
    for(long long i=1;i<=n;i++){
    	cin>>weight[i];
	}
	while(k--){
		long long int u,v;
		cin>>u>>v;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	long long int sum=0;
	for(long long int i=1;i<=n;i++){
		if(visited[i]==0){
			long long int minn=weight[i];
			dfs(i,minn);
			sum+=minn;
		}
	}
	cout<<sum;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

vector<long long int> adj[100005];
long long int visited[100005];
long long int weight[100005];
long long int dfs(long long int node,long long int w){
	visited[node]=1;
	w=min(w,weight[node]);
	for(long long int i=0;i<adj[node].size();i++){
		long long int child=adj[node][i];
		if(!visited[child]){
			dfs(child,w);
		}
	}
	return w;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    long long int n,k;
    cin>>n>>k;
    for(long long i=1;i<=n;i++){
    	cin>>weight[i];
	}
	while(k--){
		long long int u,v;
		cin>>u>>v;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	long long int sum=0;
	long long int minn;
	for(long long int i=1;i<=n;i++){
		if(visited[i]==0){
			minn=INT_MAX;
			minn=dfs(i,minn);
			sum+=minn;
		}
	}
	cout<<sum;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;
long long int minnn=INT_MAX;
vector<long long int> adj[100005];
long long int visited[100005];
long long int weight[100005];
void dfs(long long int node){
	visited[node]=1;
	minnn=min(minnn,weight[node]);
	for(long long int i=0;i<adj[node].size();i++){
		long long int child=adj[node][i];
		if(!visited[child]){
			dfs(child);
		}
	}
	return w;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    long long int n,k;
    cin>>n>>k;
    for(long long i=1;i<=n;i++){
    	cin>>weight[i];
	}
	while(k--){
		long long int u,v;
		cin>>u>>v;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	long long int sum=0;
	long long int minn;
	for(long long int i=1;i<=n;i++){
		if(visited[i]==0){
			dfs(i);
			sum+=minnn;
		}
	}
	cout<<sum;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;
long long int minnn=INT_MAX;
vector<long long int> adj[100005];
long long int visited[100005];
long long int weight[100005];
void dfs(long long int node){
	visited[node]=1;
	minnn=min(minnn,weight[node]);
	for(long long int i=0;i<adj[node].size();i++){
		long long int child=adj[node][i];
		if(!visited[child]){
			dfs(child);
		}
	}
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    long long int n,k;
    cin>>n>>k;
    for(long long i=1;i<=n;i++){
    	cin>>weight[i];
	}
	while(k--){
		long long int u,v;
		cin>>u>>v;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	long long int sum=0;
	long long int minn;
	for(long long int i=1;i<=n;i++){
		if(visited[i]==0){
		    minnn=INT_MAX;
			dfs(i);
			sum+=minnn;
		}
	}
	cout<<sum;
	return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define fastio ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
using namespace std;
ll parent[100003];
ll sz[100004];
ll c[100002];
ll n, m;

ll find(ll node){
    while (node != parent[node]){
        parent[node] = parent[parent[node]];
        node = parent[node];
    }
    return node;
}
void UN(ll n1 , ll n2){
    ll x = find (n1);
    ll y = find (n2);
    ll w = min (min(c[x], c[y]), min(c[n1], c[n2]));
    if (sz[x] < sz[y]){
        parent[x] = y;
        sz[y] += sz[x];
    }
    else{
        parent[y] = x;
        sz[x] += sz[y];
    }
    c[find(x)] = w;
}
int main(){
    fastio;
    cin >> n >> m;
    for (ll i = 1 ; i <= n ;i++)
        parent[i] = i;
    memset (sz, 0 , sizeof sz);
    for (ll i = 1 ; i <= n ; i++){
        cin >> c[i];
    }
    ll f , t;
    for (ll i = 0 ; i < m ; i++){
        cin >> f >> t;
        UN(f,t);
    }
    ll ans = c[find(1)];
    ll par = find(1);
    for (ll i = 1 ; i <= n ;i++){
        ll x = find(i);
        if (par != x){
            UN(par, x);
            ans += c[x];
        }
    }
    cout << ans ;
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define fastio ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
using namespace std;
ll cost[100003];
vector <vector<ll> > v;
vector <bool> vis;
ll dfs (ll node){
    vis[node] = 1;
    ll tmp = cost[node];
    ll child;
    for (int i = 0 ; i < v[node].size() ; i ++){
        child = v[node][i];
        if (!vis[child])
        {
            tmp = min (tmp , dfs(child));
        }
    }
    return tmp;
}
int main(){
    fastio;
    ll n , e;
    cin >> n >> e;
    v = vector <vector<ll>> (n);
    vis = vector <bool> (n);
    for (int i = 0 ; i < n ; i++)
        cin >> cost[i];
    ll f , t;
    for (ll i = 0 ; i < e ; i++){
        cin >> f >> t;
        v[f-1].push_back(t-1);
        v[t-1].push_back(f-1);
    }
    ll ans = 0;
    for (int i = 0 ; i < n ; i++){
        if (!vis[i])
            ans += dfs(i);
    }
    cout << ans;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long int
ll n,m,i,j,k,jj,r=0;
ll c[300007];
ll a[300005];
ll mm[100003][2];
int main(){
    cin>>n>>m;
    for(i=1;i<=n;i++){
        cin>>a[i];
        c[i]=a[i];
        r+=a[i];
    }
    for(i=0;i<m;i++){
       cin>>mm[i][0]>>mm[i][1];
    }
    ll rr=r;
    for(i=0;i<m;i++){
        j=mm[i][0];
        jj=mm[i][1];
        rr-=max(a[j],a[jj]);
        a[j]=min(abs(a[j]),abs(a[jj]));
        a[jj]=min(abs(a[j]),abs(a[jj]));

    }

    for(i=m-1;i>=0;--i){
        j=mm[i][0];
        jj=mm[i][1];
         r-=max(a[j],a[jj]);
        a[j]=min(abs(a[j]),abs(a[jj]));
        a[jj]=min(abs(a[j]),abs(a[jj]));

    }

    cout<<min(r,rr);
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
const int N = 1e5 + 5;
vector<int> adj[N];
int n, m, c[N];
bool vis[N];
int go(int node) {

	if (vis[node]){
		return 1e9;
	}
	 vis[node] = true;
	int ret = c[node];

		ret = min(ret,go (adj[node]));

	return ret;
}
int main() {
#ifndef ONLINE_JUDGE
	freopen("input.in", "rt", stdin);
#endif
	scanf("%d %d", &n, &m);
	for (int i = 1; i <= n; ++i) {
		scanf("%d", c + i);
	}
	while (m--) {
		int u, v;
		scanf("%d %d", &u, &v);
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	long long result = 0;
	for (int i = 1; i <= n; ++i) {
		if (!vis[i])
			result += go(i);
	}
	printf("%lld\n", result);
	return 0;
}


#include <bits/stdc++.h>

using namespace std;
const int N = 1e5 + 5;
vector<int> adj[N];
int n, m, c[N];
bool vis[N];
int go(int node) {
	vis[node]++;

	int ret = c[node];
	for (auto child: adj[node]) {
		ret = min(ret, go(child));
	}
	return ret;
}
int main() {
#ifndef ONLINE_JUDGE
	freopen("input.in", "rt", stdin);
#endif
	scanf("%d %d", &n, &m);
	for (int i = 1; i <= n; ++i) {
		scanf("%d", c + i);
	}
	while (m--) {
		int u, v;
		scanf("%d %d", &u, &v);
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	long long result = 0;
	for (int i = 1; i <= n; ++i) {
		if (!vis[i])
			result += go(i);
	}
	printf("%lld\n", result);
	return 0;
}


#include <bits/stdc++.h>

using namespace std;
const int N = 1e5 + 5;
vector<int> adj[N];
int n, m, c[N];
bool vis[N];
int go(int node) {

	if (vis[node]){
		return 1e9;
	}
	 vis[node] = true;
	int ret = c[node];
	int x = adj[node];
		ret = min(ret, go(x));

	return ret;
}
int main() {
#ifndef ONLINE_JUDGE
	freopen("input.in", "rt", stdin);
#endif
	scanf("%d %d", &n, &m);
	for (int i = 1; i <= n; ++i) {
		scanf("%d", c + i);
	}
	while (m--) {
		int u, v;
		scanf("%d %d", &u, &v);
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	long long result = 0;
	for (int i = 1; i <= n; ++i) {
		if (!vis[i])
			result += go(i);
	}
	printf("%lld\n", result);
	return 0;
}


#include <bits/stdc++.h>

using namespace std;
const int N = 1e5 + 5;
vector<int> adj[N];
int n, m, c[N];
bool vis[N];
int go(int node) {
	vis[node]==1;

	int ret = c[node];
	for (auto child: adj[node]) {
		ret = min(ret, go(child));
	}
	return ret;
}
int main() {
#ifndef ONLINE_JUDGE
	freopen("input.in", "rt", stdin);
#endif
	scanf("%d %d", &n, &m);
	for (int i = 1; i <= n; ++i) {
		scanf("%d", c + i);
	}
	while (m--) {
		int u, v;
		scanf("%d %d", &u, &v);
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	long long result = 0;
	for (int i = 1; i <= n; ++i) {
		if (!vis[i])
			result += go(i);
	}
	printf("%lld\n", result);
	return 0;
}


#include <bits/stdc++.h>

using namespace std;
const int N = 1e5 + 5;
vector<int> adj[N];
int n, m, c[N];
bool vis[N];
int go(int node) {

	if (vis[node]){
		return 1e9;
	}
	 vis[node] = true;
	int ret = c[node];

		ret = min(ret, adj[node]);

	return ret;
}
int main() {
#ifndef ONLINE_JUDGE
	freopen("input.in", "rt", stdin);
#endif
	scanf("%d %d", &n, &m);
	for (int i = 1; i <= n; ++i) {
		scanf("%d", c + i);
	}
	while (m--) {
		int u, v;
		scanf("%d %d", &u, &v);
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	long long result = 0;
	for (int i = 1; i <= n; ++i) {
		if (!vis[i])
			result += go(i);
	}
	printf("%lld\n", result);
	return 0;
}


#include <bits/stdc++.h>

using namespace std;
const int N = 1e5 + 5;
vector<int> adj[N];
int n, m, c[N];
bool vis[N];
int go(int node) {
	if (vis[node]){
	    vis[node] = true;
		return 1e9;
	}
	int ret = c[node];
	for (auto child: adj[node]) {
		ret = min(ret, go(child));
	}
	return ret;
}
int main() {
#ifndef ONLINE_JUDGE
	freopen("input.in", "rt", stdin);
#endif
	scanf("%d %d", &n, &m);
	for (int i = 1; i <= n; ++i) {
		scanf("%d", c + i);
	}
	while (m--) {
		int u, v;
		scanf("%d %d", &u, &v);
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	long long result = 0;
	for (int i = 1; i <= n; ++i) {
		if (!vis[i])
			result += go(i);
	}
	printf("%lld\n", result);
	return 0;
}


#include <bits/stdc++.h>

using namespace std;
const int N = 1e5 + 5;
vector<int> adj[N];
int n, m, c[N];
bool vis[N];
int go(int node) {

	if (vis[node]){
		return 1e9;
	}
	 vis[node] = true;
	int ret = c[node];
	for (auto child: adj[node]) {
		ret = min(ret, go(child));
	}
	return ret;
}
int main() {
#ifndef ONLINE_JUDGE
	freopen("input.in", "rt", stdin);
#endif
	scanf("%d %d", &n, &m);
	for (int i = 1; i <= n; ++i) {
		scanf("%d", c + i);
	}
	while (m--) {
		int u, v;
		scanf("%d %d", &u, &v);
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	long long result = 0;
	for (int i = 1; i <= n; ++i) {
		if (!vis[i])
			result += go(i);
	}
	printf("%lld\n", result);
	return 0;
}


#include <bits/stdc++.h>

using namespace std;
const int N = 1e5 + 5;
vector<int> adj[N];
int n, m, c[N];
bool vis[N];
int go(int node) {
    vis[node] = true;
	if (vis[node]){
		return 1e9;
	}
	int ret = c[node];
	for (auto child: adj[node]) {
		ret = min(ret, go(child));
	}
	return ret;
}
int main() {
#ifndef ONLINE_JUDGE
	freopen("input.in", "rt", stdin);
#endif
	scanf("%d %d", &n, &m);
	for (int i = 1; i <= n; ++i) {
		scanf("%d", c + i);
	}
	while (m--) {
		int u, v;
		scanf("%d %d", &u, &v);
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	long long result = 0;
	for (int i = 1; i <= n; ++i) {
		if (!vis[i])
			result += go(i);
	}
	printf("%lld\n", result);
	return 0;
}


#include <bits/stdc++.h>

using namespace std;
const int N = 1e5 + 5;
vector<int> adj[N];
int n, m, c[N];
bool vis[N];
int go(int node) {
	vis[node]++

	int ret = c[node];
	for (auto child: adj[node]) {
		ret = min(ret, go(child));
	}
	return ret;
}
int main() {
#ifndef ONLINE_JUDGE
	freopen("input.in", "rt", stdin);
#endif
	scanf("%d %d", &n, &m);
	for (int i = 1; i <= n; ++i) {
		scanf("%d", c + i);
	}
	while (m--) {
		int u, v;
		scanf("%d %d", &u, &v);
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	long long result = 0;
	for (int i = 1; i <= n; ++i) {
		if (!vis[i])
			result += go(i);
	}
	printf("%lld\n", result);
	return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int friends,pairs;
    cin>>friends>>pairs;
    freinds++;
    int coins[friends];
    int price[friends]={0};
    int visited[friends]={0};

    long long int ans=0;
    for(int i=1;i<friends;i++)
    {
        cin>>coins[i];
    }

    int first,second;
    for(int i=0;i<pairs;i++)
    {
        cin>>first>>second;

        if(visited[first])
        {
            if(price[first]>coins[second])
            {
                price[first]=coins[second];
                ans+=coins[second]-price[first];
            }
            price[second]=price[first];
            visited[second]=1;
        }
        if(visited[second])
        {
            if(price[second]>coins[first])
            {
                price[second]=coins[first];
                ans+=coins[first]-price[second];
            }
            price[first]=price[second];
            visited[first]=1;

        }

        else if(!(visited[first] || visited[second]))
        {
            price[first]=min(coins[first],coins[second]);
            price[second]=price[first];
            visited[second]=1;
            visited[first]=1;
            ans+=price[first];
        }
    }

    for(int i=1;i<friends;i++)
    {
        if(price[i]==0)
        {
            ans+=coins[i];
        }
    }
    cout<<ans;
}


#include <iostream>

using namespace std;

int main()
{
    int friends,pairs;
    cin>>friends>>pairs;

    friends++;
    int coins[friends];
    int price[friends]={0};
    int visited[friends]={0};

    long long int ans=0;
    for(int i=1;i<friends;i++)
    {
        cin>>coins[i];
    }

    int first,second;
    for(int i=0;i<pairs;i++)
    {
        cin>>first>>second;

        if(visited[first] && !visited[second])
        {
            if(price[first]>coins[second])
            {
                ans+=coins[second]-price[first];
                price[first]=coins[second];
            }
            price[second]=price[first];
            visited[second]=1;
        }
        else if(visited[second] && !visited[first])
        {
            if(price[second]>coins[first])
            {
                ans+=coins[first]-price[second];
                price[second]=coins[first];
            }
            price[first]=price[second];
            visited[first]=1;

        }

        else if(!(visited[first] || visited[second]))
        {
            price[first]=min(coins[first],coins[second]);
            price[second]=price[first];
            visited[second]=1;
            visited[first]=1;
            ans+=price[first];
        }
        else
        {
            if(price[first]==price[second])
            ans-=(price[first]);
            else
            ans-=(price[first]+price[second]);

            price[first]=min(price[first],price[second]);
            price[second]=price[first];
            ans+=price[first];
        }
    }

    for(int i=1;i<friends;i++)
    {
        if(price[i]==0)
        {
            ans+=coins[i];
        }
    }
    cout<<ans;
}


#include <iostream>

using namespace std;

int main()
{
    int friends,pairs;
    cin>>friends>>pairs;

    friends++;
    int coins[friends];
    int price[friends]={0};
    int visited[friends]={0};

    long long int ans=0;
    for(int i=1;i<friends;i++)
    {
        cin>>coins[i];
    }

    int first,second;
    for(int i=0;i<pairs;i++)
    {
        cin>>first>>second;

        if(visited[first] && !visited[second])
        {
            if(price[first]>coins[second])
            {
                ans+=coins[second]-price[first];
                price[first]=coins[second];
            }
            price[second]=price[first];
            visited[second]=1;
        }
        else if(visited[second] && !visited[first])
        {
            if(price[second]>coins[first])
            {
                ans+=coins[first]-price[second];
                price[second]=coins[first];
            }
            price[first]=price[second];
            visited[first]=1;

        }

        else if(!(visited[first] || visited[second]))
        {
            price[first]=min(coins[first],coins[second]);
            price[second]=price[first];
            visited[second]=1;
            visited[first]=1;
            ans+=price[first];
        }
        else
        {
            ans-=(price[first]+price[second]);
            price[first]=min(price[first],price[second]);
            price[second]=price[first];
            ans+=price[first];
        }
    }

    for(int i=1;i<friends;i++)
    {
        if(price[i]==0)
        {
            ans+=coins[i];
        }
    }
    cout<<ans;
}


#include <iostream>

using namespace std;

int main()
{
    int friends,pairs;
    cin>>friends>>pairs;
    friends++;
    int coins[friends];
    int price[friends]={0};
    int visited[friends]={0};

    long long int ans=0;
    for(int i=1;i<friends;i++)
    {
        cin>>coins[i];
    }

    int first,second;
    for(int i=0;i<pairs;i++)
    {
        cin>>first>>second;

        if(visited[first] && !visited[second])
        {
            if(price[first]>coins[second])
            {
                ans+=coins[second]-price[first];
                price[first]=coins[second];
            }
            price[second]=price[first];
            visited[second]=1;
        }
        else if(visited[second] && !visited[first])
        {
            if(price[second]>coins[first])
            {
                ans+=coins[first]-price[second];
                price[second]=coins[first];
            }
            price[first]=price[second];
            visited[first]=1;

        }

        else if(!(visited[first] || visited[second]))
        {
            price[first]=min(coins[first],coins[second]);
            price[second]=price[first];
            visited[second]=1;
            visited[first]=1;
            ans+=price[first];
        }
        else
        {
            ans-=max(price[first],price[second]);
            price[first]=min(price[first],price[second]);
            price[second]=min(price[first],price[second]);
            ans+=price[first];
        }
    }

    for(int i=1;i<friends;i++)
    {
        if(price[i]==0)
        {
            ans+=coins[i];
        }
    }
    cout<<ans;
}