#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define scs(a) scanf("%s",a)
#define sc1(a) scanf("%d",&a)
#define sc2(a,b) scanf("%d %d",&a,&b)
#define sc3(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define sc1l(a) scanf("%lld",&a)
#define sc2l(a,b) scanf("%lld %lld",&a,&b)
#define sc3l(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define pf1(a) printf("%d",a);
#define pf2(a,b) printf("%d %d",a,b);
#define pf1l(a) printf("%lld",a);
#define pf2l(a,b) printf("%lld %lld",a,b);
#define pf printf
#define sc scanf
#define br printf("\n");
#define Forl(i,a,b) for(i=a;i<b;i++)
#define Fore(i,a,b) for(i=a;i<=b;i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
const double PI=acos(-1.0);
#define mem0(a) memset(a,0,sizeof(a))
#define mem1(a) memset(a,-1,sizeof(a))
template <typename T,typename TT>void debug(T a[],TT n){for(TT i=0;i<n;i++)cout<<a[i]<<" ";br;}
template <typename T>T Find(T a[],T z){return a[z]=(a[z]==z)?a[z]:Find(a,a[z]);}
#define pii pair<int,int>
int inline set_bit(int mask,int i){return mask=mask|(1<<i);}
int inline reset_bit(int mask,int i){return mask=mask&~(1<<i);}
bool inline check_bit(int mask,int i){return mask&(1<<i);}

ll inline gcd(ll a,ll b){return !b?abs(a):gcd(b,a%b);}
ll inline lcm(ll a,ll b){return (a/gcd(a,b)*b);}
ll bigmod(ll a,ll b,ll m){
    if(!b)return 1%m;
    if(b%2)return (a%m*bigmod(a,b-1,m))%m;
    else {ll x=bigmod(a,b/2,m)%m;return (x*x)%m;}
}
ll power(ll a,ll b){
    if(!b)return 1;
    if(b%2)return a*power(a,b-1);
    else {ll x=power(a,b/2);return x*x;}
}

int ans;
void dfs(int u,vector<int>vec[],bool *vis,int *arr){
    vis[u]=true;
    set<int>st;
    for(int i=0;i<vec[u].size();i++){
        if(!vis[vec[u][i]]){
            dfs(vec[u][i],vec,vis,arr);
            st.insert(arr[vec[u][i]]);
        }
    }
    //pf1(st.size());
    //br;
    if(st.find(arr[u])!=st.end())ans+=st.size()-1;
    else ans+=st.size();
    //st.clear();
}
int main(){
    int n,m,k;
    while(3==sc3(n,m,k)){
        int arr[n+5],l,r;
        bool vis[n+5];
        for(int i=1;i<=n;i++){
            sc1(arr[i]);
            vis[i]=false;
        }
        ans=0;
        vector<int>vec[n*2+10];
        for(int i=1;i<=m;i++){
            sc2(l,r);
            vec[l].pb(r);
            vec[r].pb(l);
        }
        for(int i=1;i<=n;i++)if(!vis[i])dfs(i,vec,vis,arr);
        pf1(ans);
        br;
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define scs(a) scanf("%s",a)
#define sc1(a) scanf("%d",&a)
#define sc2(a,b) scanf("%d %d",&a,&b)
#define sc3(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define sc1l(a) scanf("%lld",&a)
#define sc2l(a,b) scanf("%lld %lld",&a,&b)
#define sc3l(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define pf1(a) printf("%d",a);
#define pf2(a,b) printf("%d %d",a,b);
#define pf1l(a) printf("%lld",a);
#define pf2l(a,b) printf("%lld %lld",a,b);
#define pf printf
#define sc scanf
#define br printf("\n");
#define Forl(i,a,b) for(i=a;i<b;i++)
#define Fore(i,a,b) for(i=a;i<=b;i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
const double PI=acos(-1.0);
#define mem0(a) memset(a,0,sizeof(a))
#define mem1(a) memset(a,-1,sizeof(a))
template <typename T,typename TT>void debug(T a[],TT n){for(TT i=0;i<n;i++)cout<<a[i]<<" ";br;}
template <typename T>T Find(T a[],T z){return a[z]=(a[z]==z)?a[z]:Find(a,a[z]);}
#define pii pair<int,int>
int inline set_bit(int mask,int i){return mask=mask|(1<<i);}
int inline reset_bit(int mask,int i){return mask=mask&~(1<<i);}
bool inline check_bit(int mask,int i){return mask&(1<<i);}

ll inline gcd(ll a,ll b){return !b?abs(a):gcd(b,a%b);}
ll inline lcm(ll a,ll b){return (a/gcd(a,b)*b);}
ll bigmod(ll a,ll b,ll m){
    if(!b)return 1%m;
    if(b%2)return (a%m*bigmod(a,b-1,m))%m;
    else {ll x=bigmod(a,b/2,m)%m;return (x*x)%m;}
}
ll power(ll a,ll b){
    if(!b)return 1;
    if(b%2)return a*power(a,b-1);
    else {ll x=power(a,b/2);return x*x;}
}

int main(){
    int n,m,k;
    while(3==sc3(n,m,k)){
        int arr[n+5],l,r;
        int parent[n+5];
        for(int i=1;i<=n;i++){
            sc1(arr[i]);
            parent[i]=arr[i];
        }
        int ans=0;
        vector<pii>vec;
        for(int i=0;i<m;i++){
            sc2(l,r);
            vec.pb(mp(l,r));
        }
        sort(vec.begin(),vec.end());
        for(int i=0;i<m;i++){
            l=vec[i].F;
            r=vec[i].S;
            int u=Find(parent,l);
            int v=Find(parent,r);
            if(u!=v){
                if(u<=k || v<=k){
                    if(u<=k){
                        parent[v]=u;
                        ans++;
                    }
                    else if(v<=k){
                        parent[u]=v;
                        ans++;
                    }
                }
                else {
                    parent[u]=k;
                    parent[v]=k;
                    ans+=2;
                }
            }
            else {
                if(u>k){
                    ans++;
                    parent[u]=k;
                    parent[v]=k;
                }
            }
        }
        pf1(ans);
        br;
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define scs(a) scanf("%s",a)
#define sc1(a) scanf("%d",&a)
#define sc2(a,b) scanf("%d %d",&a,&b)
#define sc3(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define sc1l(a) scanf("%lld",&a)
#define sc2l(a,b) scanf("%lld %lld",&a,&b)
#define sc3l(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define pf1(a) printf("%d",a);
#define pf2(a,b) printf("%d %d",a,b);
#define pf1l(a) printf("%lld",a);
#define pf2l(a,b) printf("%lld %lld",a,b);
#define pf printf
#define sc scanf
#define br printf("\n");
#define Forl(i,a,b) for(i=a;i<b;i++)
#define Fore(i,a,b) for(i=a;i<=b;i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
const double PI=acos(-1.0);
#define mem0(a) memset(a,0,sizeof(a))
#define mem1(a) memset(a,-1,sizeof(a))
template <typename T,typename TT>void debug(T a[],TT n){for(TT i=0;i<n;i++)cout<<a[i]<<" ";br;}
template <typename T>T Find(T a[],T z){return a[z]=(a[z]==z)?a[z]:Find(a,a[z]);}
#define pii pair<int,int>
int inline set_bit(int mask,int i){return mask=mask|(1<<i);}
int inline reset_bit(int mask,int i){return mask=mask&~(1<<i);}
bool inline check_bit(int mask,int i){return mask&(1<<i);}

ll inline gcd(ll a,ll b){return !b?abs(a):gcd(b,a%b);}
ll inline lcm(ll a,ll b){return (a/gcd(a,b)*b);}
ll bigmod(ll a,ll b,ll m){
    if(!b)return 1%m;
    if(b%2)return (a%m*bigmod(a,b-1,m))%m;
    else {ll x=bigmod(a,b/2,m)%m;return (x*x)%m;}
}
ll power(ll a,ll b){
    if(!b)return 1;
    if(b%2)return a*power(a,b-1);
    else {ll x=power(a,b/2);return x*x;}
}

int maxi,total;
void dfs(int u,vector<int>vec[],bool *vis,int *arr,map<int,int>&color){
    total++;
    color[arr[u]]++;
    maxi=max(maxi,color[arr[u]]);
    vis[u]=true;
    for(int i=0;i<vec[u].size();i++){
        if(!vis[vec[u][i]]){
            dfs(vec[u][i],vec,vis,arr,color);
        }
    }
}
int main(){
    int n,m,k;
    while(3==sc3(n,m,k)){
        int arr[n+5],l,r;
        bool vis[n+5];
        for(int i=1;i<=n;i++){
            sc1(arr[i]);
            vis[i]=false;
        }
        vector<int>vec[n*2+10];
        //int color[m+5];
        for(int i=1;i<=m;i++){
            sc2(l,r);
            vec[l].pb(r);
            vec[r].pb(l);
            //color[i]=0;
        }
        int ans=0;
        for(int i=1;i<=n;i++){
            map<int,int>color;
            if(!vis[i]){
                total=0;
                maxi=0;
                dfs(i,vec,vis,arr,color);
                ans+=total-maxi;
            }
        }
        pf1(ans);
        br;
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define scs(a) scanf("%s",a)
#define sc1(a) scanf("%d",&a)
#define sc2(a,b) scanf("%d %d",&a,&b)
#define sc3(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define sc1l(a) scanf("%lld",&a)
#define sc2l(a,b) scanf("%lld %lld",&a,&b)
#define sc3l(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define pf1(a) printf("%d",a);
#define pf2(a,b) printf("%d %d",a,b);
#define pf1l(a) printf("%lld",a);
#define pf2l(a,b) printf("%lld %lld",a,b);
#define pf printf
#define sc scanf
#define br printf("\n");
#define Forl(i,a,b) for(i=a;i<b;i++)
#define Fore(i,a,b) for(i=a;i<=b;i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
const double PI=acos(-1.0);
#define mem0(a) memset(a,0,sizeof(a))
#define mem1(a) memset(a,-1,sizeof(a))
template <typename T,typename TT>void debug(T a[],TT n){for(TT i=0;i<n;i++)cout<<a[i]<<" ";br;}
template <typename T>T Find(T a[],T z){return a[z]=(a[z]==z)?a[z]:Find(a,a[z]);}
#define pii pair<int,int>
int inline set_bit(int mask,int i){return mask=mask|(1<<i);}
int inline reset_bit(int mask,int i){return mask=mask&~(1<<i);}
bool inline check_bit(int mask,int i){return mask&(1<<i);}

ll inline gcd(ll a,ll b){return !b?abs(a):gcd(b,a%b);}
ll inline lcm(ll a,ll b){return (a/gcd(a,b)*b);}
ll bigmod(ll a,ll b,ll m){
    if(!b)return 1%m;
    if(b%2)return (a%m*bigmod(a,b-1,m))%m;
    else {ll x=bigmod(a,b/2,m)%m;return (x*x)%m;}
}
ll power(ll a,ll b){
    if(!b)return 1;
    if(b%2)return a*power(a,b-1);
    else {ll x=power(a,b/2);return x*x;}
}

void dfs(int u,vector<int>vec[],bool *vis,set<int>&st,int *arr){
    vis[u]=true;
    st.insert(arr[u]);
    for(int i=0;i<vec[u].size();i++){
        if(!vis[vec[u][i]]){
            dfs(vec[u][i],vec,vis,st,arr);
        }
    }
}
int main(){
    int n,m,k;
    while(3==sc3(n,m,k)){
        int arr[n+5],l,r;
        bool vis[n+5];
        for(int i=1;i<=n;i++){
            sc1(arr[i]);
            vis[i]=false;
        }
        int ans=0;
        vector<int>vec[n*2+10];
        for(int i=1;i<=m;i++){
            sc2(l,r);
            vec[l].pb(r);
            vec[r].pb(l);
        }
        for(int i=1;i<=n;i++){
            if(!vis[i]){
                set<int>st;
                dfs(i,vec,vis,st,arr);
                //pf1(st.size());
                //br;
                ans+=st.size()-1;
            }
        }
        pf1(ans);
        br;
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define scs(a) scanf("%s",a)
#define sc1(a) scanf("%d",&a)
#define sc2(a,b) scanf("%d %d",&a,&b)
#define sc3(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define sc1l(a) scanf("%lld",&a)
#define sc2l(a,b) scanf("%lld %lld",&a,&b)
#define sc3l(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define pf1(a) printf("%d",a);
#define pf2(a,b) printf("%d %d",a,b);
#define pf1l(a) printf("%lld",a);
#define pf2l(a,b) printf("%lld %lld",a,b);
#define pf printf
#define sc scanf
#define br printf("\n");
#define Forl(i,a,b) for(i=a;i<b;i++)
#define Fore(i,a,b) for(i=a;i<=b;i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
const double PI=acos(-1.0);
#define mem0(a) memset(a,0,sizeof(a))
#define mem1(a) memset(a,-1,sizeof(a))
template <typename T,typename TT>void debug(T a[],TT n){for(TT i=0;i<n;i++)cout<<a[i]<<" ";br;}
template <typename T>T Find(T a[],T z){return a[z]=(a[z]==z)?a[z]:Find(a,a[z]);}
#define pii pair<int,int>
int inline set_bit(int mask,int i){return mask=mask|(1<<i);}
int inline reset_bit(int mask,int i){return mask=mask&~(1<<i);}
bool inline check_bit(int mask,int i){return mask&(1<<i);}

ll inline gcd(ll a,ll b){return !b?abs(a):gcd(b,a%b);}
ll inline lcm(ll a,ll b){return (a/gcd(a,b)*b);}
ll bigmod(ll a,ll b,ll m){
    if(!b)return 1%m;
    if(b%2)return (a%m*bigmod(a,b-1,m))%m;
    else {ll x=bigmod(a,b/2,m)%m;return (x*x)%m;}
}
ll power(ll a,ll b){
    if(!b)return 1;
    if(b%2)return a*power(a,b-1);
    else {ll x=power(a,b/2);return x*x;}
}

int main(){
    int n,m,k;
    while(3==sc3(n,m,k)){
        int arr[n+5],l,r;
        int parent[n+5];
        for(int i=1;i<=n;i++){
            sc1(arr[i]);
            parent[i]=i;
        }
        int ans=0;
        vector<pii>vec;
        for(int i=0;i<m;i++){
            sc2(l,r);
            vec.pb(mp(l,r));
        }
        sort(vec.begin(),vec.end());
        for(int i=0;i<m;i++){
            l=vec[i].F;
            r=vec[i].S;
            int u=Find(parent,arr[l]);
            int v=Find(parent,arr[r]);
            if(u!=v){
                if(u<=k || v<=k){
                    if(u<=k){
                        parent[v]=u;
                        ans++;
                    }
                    else if(v<=k){
                        parent[u]=v;
                        ans++;
                    }
                }
                else {
                    parent[u]=Find(parent,1);
                    parent[v]=Find(parent,1);
                    ans+=2;
                }
            }
        }
        pf1(ans);
        br;
    }

    return 0;
}


/*input
3 2 3
1 2 3
1 2
2 3
*/
#include <iostream>
#include <cstdio>
#include <vector>
#include <bitset>
#include <algorithm>

#define pb push_back
#define mp make_pair

using namespace std;

const int MAXN = 200000 + 8;

int n, m, k, cnt = 0, x, y;
int C[MAXN];
vector<int> A[MAXN];
vector<int> B[MAXN];
bool visited[MAXN];

void dfs (int v, int num) {
    B[num].pb(C[v]);
    visited[v] = false;
    for (int i = 0; i < A[v].size(); i++)
        if (visited[A[v][i]] == true)
            dfs(A[v][i], num);
}

int count_colors (vector<int> V) {
    int x = 1, res = 1;
    for (int i = 0; i < V.size() - 1; i++) {
        if (V[i] == V[i + 1]) x++;
        else {
            res = max(res, x);
            x = 1;
        }
    }
    return V.size() - res;
}

int main () {
    for (int i = 0; i < n; i++) visited[i] = false;

    scanf("%d %d %d", &n, &m, &k);
    for (int i = 0; i < n; i++) scanf("%d", &C[i]);
    for (int i = 0; i < m; i++) {
        scanf("%d %d", &x, &y);
        x--; y--;
        A[x].pb(y);
        A[y].pb(x);
        visited[x] = true;
        visited[y] = true;
    }
    for (int i = 0; i < n; i++)
        if (visited[i] == true)
            dfs(i, cnt++);

    int res = 0;
    for (int i = 0; i < cnt; i++) res += count_colors(B[i]);
    cout << res << endl;

    return 0;
}


/*input
3 2 2
1 1 2
1 2
2 1
*/
#include <iostream>
#include <cstdio>
#include <vector>
#include <bitset>
#include <algorithm>

#define pb push_back
#define mp make_pair

using namespace std;

const int MAXN = 200000 + 8;

int n, m, k, cnt = 0, x, y;
int C[MAXN], P[MAXN];
vector<int> A[MAXN];
bitset<MAXN> mark;
bitset<MAXN> used;

void dfs (int x) {
    for (int i = 0; i < A[x].size(); i++) {
        int y = A[x][i];
        if (P[y] == 0) {
            P[y] = P[x];
            dfs(y);
        }
    }
}

int max_colors (vector<int> V) {
    sort(V.begin(), V.end());
    V.pb(-1);
    int x = 0, y = 0, z = 0;
    while (x < V.size()) {
        while (V[y] == V[x]) y++;
        z = max(z, y - x);
        x = y;
    }
    return z;
}

int main () {

    for (int i = 0; i < n; i++) P[i] = -1;

    scanf("%d %d %d", &n, &m, &k);
    for (int i = 0; i < n; i++) scanf("%d", &C[i]);
    for (int i = 0; i < m; i++) {
        scanf("%d %d", &x, &y);
        x--; y--;
        A[x].pb(y);
        A[y].pb(x);
        P[x] = P[y] = 0;
        // cout << x << " " << y << " " << used[x] << " " << used[y] << endl;
    }
    for (int i = 0; i < n; i++) {
        if (P[i] == 0) {
            P[i] = ++cnt;
            dfs(i);
        }
    }

    for (int i = 0; i <= cnt; i++) A[i].clear();
    for (int i = 0; i < n; i++) A[P[i]].pb(C[i]);

    int res = 0;
    for (int i = 1; i <= cnt; i++) res += A[i].size() - max_colors(A[i]);
    cout << res << endl;

    return 0;
}


/*input
8 7 8
1 1 3 4 5 6 1 1
1 8
1 2
2 8
8 7
6 5
5 4
3 4
*/
#include <iostream>
#include <cstdio>
#include <vector>
#include <bitset>
#include <algorithm>

using namespace std;

const int MAXN = 200000 + 8;
struct Group {
	int color, id;
	Group() {}
	Group(int _c, int _i) { color = _c, id = _i; }
	bool operator == (Group x) {
		return (x.id == id and x.color == color);
	}
};
int compare_group(Group a, Group b) {
	if (a.id < b.id) return -1;
	if (a.id == b.id) return 0;
	return 1;
}

int n, m, k, x, y;
Group G[MAXN];
int C[MAXN], D[MAXN];
vector<int> linked[MAXN];
bitset<MAXN> mark;

void find_component(int x, int id) {
	C[id]++;
	mark[x] = 1;
	G[x].id = id;
	for (int i = 0; i < linked[x].size(); i++)
		if (mark[linked[x][i]] == 0)
			find_component(linked[x][i], id);
}

int main() {

	scanf("%d %d %d", &n, &m, &k);
	for (int i = 0; i < n; i++) {
		scanf("%d", &x);
		G[i].color = x;
	}
	for (int i = 0; i < m; i++) {
		scanf("%d %d", &x, &y);
		x--; y--;
		linked[x].push_back(y);
		linked[y].push_back(x);
	}

	mark = 0;
	int counter = 0;
	for (int i = 0; i < n; i++)
		if (mark[i] == 0) find_component(i, ++counter);
	sort(G, G + n, compare_group);

	G[n] = Group(MAXN, MAXN);
	int a, b = 0;
	while (a < n) {
		b = a + 1;
		while (G[b] == G[a]) b++;
		D[G[a].id] = max(D[G[a].id], b - a);
		a = b;
	}
	int res = 0;
	for (int i = 0; i < n; i++) res += C[i] - D[i];
	printf("%d\n", res);

	// for (int i = 0; i <= n; i++) cout << G[i].color << " " << G[i].id << endl; cout << "-----" << endl;
	// for (int i = 0; i < n; i++) cout << D[i] << " " << C[i] << endl;

	return 0;
}


/*input
10 3 2
2 1 1 2 1 1 2 1 2 2
4 10
9 3
5 7
*/
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

const int MAXN = 200000 + 8;
struct Group {
	int color, id;
	Group() {}
	Group(int _c, int _i) { color = _c, id = _i; }
	bool operator == (Group x) { return (x.id == id and x.color == color); }
};
int compare_group(Group a, Group b) {
	if (a.id < b.id) return -1;
	if (a.id == b.id) {
		// if (a.color < b.color) return -1;
		// if (a.color > b.color) return 1;
		return 0;
	}
	return 1;
}

int n, m, k, x, y;
Group G[MAXN];
int C[MAXN], D[MAXN];
vector<int> linked[MAXN];
bool mark[MAXN];

void find_component(int x, int id) {
	C[id]++;
	mark[x] = 1;
	G[x].id = id;
	for (int i = 0; i < linked[x].size(); i++)
		if (mark[linked[x][i]] == 0)
			find_component(linked[x][i], id);
}

int main() {

	scanf("%d %d %d", &n, &m, &k);
	for (int i = 0; i < n; i++) {
		scanf("%d", &x);
		G[i].color = x;
	}
	for (int i = 0; i < m; i++) {
		scanf("%d %d", &x, &y);
		x--; y--;
		linked[x].push_back(y);
		linked[y].push_back(x);
	}

	for (int i = 0; i < n; i++) mark[i] = 0;
	int counter = 0;
	for (int i = 0; i < n; i++)
		if (mark[i] == 0) find_component(i, ++counter);

	G[n] = Group(MAXN, MAXN);
	sort(G, G + n, compare_group);
	int a, b = 0;
	while (a < n) {
		b = a + 1;
		while (G[b] == G[a]) b++;
		D[G[a].id] = max(D[G[a].id], b - a);
		a = b;
	}
	int res = 0;
	for (int i = 0; i < n; i++) res += C[i] - D[i];
	printf("%d\n", res);

	// for (int i = 0; i < n; i++) cout << G[i].color << " " << G[i].id << endl; cout << "-----" << endl;
	// for (int i = 0; i < n; i++) cout << D[i] << " "; cout << endl;
	// for (int i = 0; i < n; i++) cout << C[i] << " "; cout << endl;

	return 0;
}


/*input
3 2 2
1 1 2
1 2
2 1
*/
#include <iostream>
#include <cstdio>
#include <vector>
#include <bitset>
#include <algorithm>

#define pb push_back
#define mp make_pair

using namespace std;

const int MAXN = 200000 + 8;

int n, m, k, cnt = 0, x, y;
int C[MAXN];
vector<int> A[MAXN];
vector<int> B[MAXN];
bool visited[MAXN];

void dfs (int v, int num) {
    B[num].pb(C[v]);
    visited[v] = false;
    for (int i = 0; i < A[v].size(); i++)
        if (visited[A[v][i]] == true)
            dfs(A[v][i], num);
}

int count_colors (vector<int> V) {
    int x = 1, res = 1;
    sort(V.begin(), V.end());
    // for (int i = 0; i < V.size(); i++) cout << V[i] << " "; cout << endl;
    for (int i = 0; i < V.size() - 1; i++) {
        if (V[i] == V[i + 1]) x++;
        else {
            res = max(res, x);
            x = 1;
        }
    }
    return V.size() - max(res, x);
}

int main () {
    for (int i = 0; i < n; i++) visited[i] = false;

    scanf("%d %d %d", &n, &m, &k);
    for (int i = 0; i < n; i++) scanf("%d", &C[i]);
    for (int i = 0; i < m; i++) {
        scanf("%d %d", &x, &y);
        x--; y--;
        A[x].pb(y);
        A[y].pb(x);
        visited[x] = true;
        visited[y] = true;
    }
    for (int i = 0; i < n; i++)
        if (visited[i] == true)
            dfs(i, cnt++);

    int res = 0;
    for (int i = 0; i < cnt; i++) res += count_colors(B[i]);
    cout << res << endl;

    return 0;
}


/*input
3 2 2
1 1 2
1 2
2 1
*/
#include <iostream>
#include <cstdio>
#include <vector>
#include <bitset>

#define pb push_back
#define mp make_pair

using namespace std;

const int MAXN = 200000 + 8;

int n, m, k, cnt = 0, x, y;
int C[MAXN], P[MAXN];
vector<int> A[MAXN];
bitset<MAXN> mark;
bitset<MAXN> used;

void dfs (int x) {
    for (int i = 0; i < A[x].size(); i++) {
        int y = A[x][i];
        if (mark[y] == 0) {
            mark[y] = 1;
            P[y] = P[x];
            dfs(y);
        }
    }
}

int max_colors (vector<int> V) {
    sort(V.begin(), V.end());
    V.pb(-1);
    int x = 0, y = 0, z = 0;
    while (x < V.size()) {
        while (V[y] == V[x]) y++;
        z = max(z, y - x);
        x = y;
    }
    return z;
}

int main () {

    used = 0;
    mark = 0;

    scanf("%d %d %d", &n, &m, &k);
    for (int i = 0; i < n; i++) scanf("%d", &C[i]);
    for (int i = 0; i < m; i++) {
        scanf("%d %d", &x, &y);
        x--; y--;
        A[x].pb(y);
        A[y].pb(x);
        used[x] = 1; used[y] = 1;
        // cout << x << " " << y << " " << used[x] << " " << used[y] << endl;
    }
    for (int i = 0; i < n; i++) {
        if (used[i] && P[i] == 0) {
            P[i] = ++cnt;
            dfs(i);
        }
    }

    for (int i = 0; i <= cnt; i++) A[i].clear();
    for (int i = 0; i < n; i++) A[P[i]].pb(C[i]);

    int res = 0;
    for (int i = 1; i <= cnt; i++) {
        res += A[i].size() - max_colors(A[i]);
    }
    cout << res << endl;
    return 0;
}


/*input
3 2 3
1 2 3
1 2
2 3
*/
#include <iostream>
#include <cstdio>
#include <vector>
#include <bitset>
#include <algorithm>

#define pb push_back
#define mp make_pair

using namespace std;

const int MAXN = 200000 + 8;

int n, m, k, cnt = 0, x, y;
int C[MAXN];
vector<int> A[MAXN];
vector<int> B[MAXN];
bool visited[MAXN];

void dfs (int v, int num) {
    B[num].pb(C[v]);
    visited[v] = false;
    for (int i = 0; i < A[v].size(); i++)
        if (visited[A[v][i]] == true)
            dfs(A[v][i], num);
}

int count_colors (vector<int> V) {
    if (V.size() < 2) return 0;
    int tmp = V.size();
    sort(V.begin(), V.end());
    V.pb(-1);
    int x = 0, y = 0, z = 0;
    while (x < V.size()) {
        while (V[y] == V[x]) y++;
        z = max(z, y - x);
        x = y;
    }
    return tmp - z;
}

int main () {
    for (int i = 0; i < n; i++) visited[i] = false;

    scanf("%d %d %d", &n, &m, &k);
    for (int i = 0; i < n; i++) scanf("%d", &C[i]);
    for (int i = 0; i < m; i++) {
        scanf("%d %d", &x, &y);
        x--; y--;
        A[x].pb(y);
        A[y].pb(x);
        visited[x] = true;
        visited[y] = true;
    }
    for (int i = 0; i < n; i++)
        if (visited[i] == true)
            dfs(i, cnt++);

    int res = 0;
    for (int i = 0; i < cnt; i++) res += count_colors(B[i]);
    cout << res << endl;

    return 0;
}


/*input
10 3 2
2 1 1 2 1 1 2 1 2 2
4 10
9 3
5 7
*/
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

const int MAXN = 200000 + 8;
struct Group {
	int color, id;
	Group() {}
	Group(int _c, int _i) { color = _c, id = _i; }
	bool operator == (Group x) { return (x.id == id and x.color == color); }
};
int compare_group(Group a, Group b) {
	if (a.id < b.id) return -1;
	if (a.id == b.id) {
		if (a.color < b.color) return -1;
		if (a.color > b.color) return 1;
		return 0;
	}
	return 1;
}

int n, m, k, x, y;
Group G[MAXN];
int C[MAXN], D[MAXN];
vector<int> linked[MAXN];
bool mark[MAXN];

void find_component(int x, int id) {
	C[id]++;
	mark[x] = 1;
	G[x].id = id;
	for (int i = 0; i < linked[x].size(); i++)
		if (mark[linked[x][i]] == 0)
			find_component(linked[x][i], id);
}

int main() {

	for (int i = 0; i < MAXN; i++) {
		D[i] = C[i] = 0;
		mark[i] = 0;

	}

	scanf("%d %d %d", &n, &m, &k);
	for (int i = 0; i < n; i++) {
		scanf("%d", &x);
		G[i].color = x;
	}
	for (int i = 0; i < m; i++) {
		scanf("%d %d", &x, &y);
		x--; y--;
		linked[x].push_back(y);
		linked[y].push_back(x);
	}

	int counter = 0;
	for (int i = 0; i < n; i++)
		if (mark[i] == 0) find_component(i, ++counter);

	G[n] = Group(MAXN, MAXN);
	sort(G, G + n, compare_group);
	int a, b = 0;
	while (a < n) {
		b = a + 1;
		while (G[b] == G[a]) b++;
		D[G[a].id] = max(D[G[a].id], b - a);
		a = b;
	}
	int res = 0;
	for (int i = 0; i < n; i++) res += C[i] - D[i];
	printf("%d\n", res);

	// for (int i = 0; i < n; i++) cout << G[i].color << " " << G[i].id << endl; cout << "-----" << endl;
	// for (int i = 0; i < n; i++) cout << D[i] << " "; cout << endl;
	// for (int i = 0; i < n; i++) cout << C[i] << " "; cout << endl;

	return 0;
}


/*input
3 2 2
1 1 2
1 2
2 1
*/
#include <iostream>
#include <cstdio>
#include <vector>
#include <bitset>
#include <algorithm>

#define pb push_back
#define mp make_pair

using namespace std;

const int MAXN = 200000 + 8;

int n, m, k, cnt = 0, x, y;
int C[MAXN], P[MAXN];
vector<int> A[MAXN];
bitset<MAXN> mark;
bitset<MAXN> used;

void dfs (int x) {
    for (int i = 0; i < A[x].size(); i++) {
        int y = A[x][i];
        if (mark[y] == 0) {
            mark[y] = 1;
            P[y] = P[x];
            dfs(y);
        }
    }
}

int max_colors (vector<int> V) {
    sort(V.begin(), V.end());
    V.pb(-1);
    int x = 0, y = 0, z = 0;
    while (x < V.size()) {
        while (V[y] == V[x]) y++;
        z = max(z, y - x);
        x = y;
    }
    return z;
}

int main () {

    used = 0;
    mark = 0;

    scanf("%d %d %d", &n, &m, &k);
    for (int i = 0; i < n; i++) scanf("%d", &C[i]);
    for (int i = 0; i < m; i++) {
        scanf("%d %d", &x, &y);
        x--; y--;
        A[x].pb(y);
        A[y].pb(x);
        used[x] = 1; used[y] = 1;
        // cout << x << " " << y << " " << used[x] << " " << used[y] << endl;
    }
    for (int i = 0; i < n; i++) {
        if (used[i] && P[i] == 0) {
            P[i] = ++cnt;
            dfs(i);
        }
    }

    for (int i = 0; i <= cnt; i++) A[i].clear();
    for (int i = 0; i < n; i++) A[P[i]].pb(C[i]);

    int res = 0;
    for (int i = 1; i <= cnt; i++) {
        res += A[i].size() - max_colors(A[i]);
    }
    cout << res << endl;
    return 0;
}


/*input
10 3 2
2 1 1 2 1 1 2 1 2 2
4 10
9 3
5 7
*/
#include <iostream>
#include <cstdio>
#include <vector>
#include <bitset>
#include <algorithm>

using namespace std;

const int MAXN = 200000 + 8;
struct Group {
	int color, id;
	Group() {}
	Group(int _c, int _i) { color = _c, id = _i; }
	bool operator == (Group x) { return (x.id == id and x.color == color); }
};
int compare_group(Group a, Group b) {
	if (a.id < b.id) return -1;
	if (a.id == b.id) {
		if (a.color < b.color) return -1;
		if (a.color > b.color) return 1;
		return 0;
	}
	return 1;
}

int n, m, k, x, y;
Group G[MAXN];
int C[MAXN], D[MAXN];
vector<int> linked[MAXN];
bitset<MAXN> mark;

void find_component(int x, int id) {
	C[id]++;
	mark[x] = 1;
	G[x].id = id;
	for (int i = 0; i < linked[x].size(); i++)
		if (mark[linked[x][i]] == 0)
			find_component(linked[x][i], id);
}

int main() {

	scanf("%d %d %d", &n, &m, &k);
	for (int i = 0; i < n; i++) {
		scanf("%d", &x);
		G[i].color = x;
	}
	for (int i = 0; i < m; i++) {
		scanf("%d %d", &x, &y);
		x--; y--;
		linked[x].push_back(y);
		linked[y].push_back(x);
	}

	mark = 0;
	int counter = 0;
	for (int i = 0; i < n; i++)
		if (mark[i] == 0) find_component(i, ++counter);
	sort(G, G + n, compare_group);

	G[n] = Group(MAXN, MAXN);
	int a, b = 0;
	while (a < n) {
		b = a + 1;
		while (G[b] == G[a]) b++;
		D[G[a].id] = max(D[G[a].id], b - a);
		a = b;
	}
	int res = 0;
	for (int i = 0; i < n; i++) res += C[i] - D[i];
	printf("%d\n", res);

	// for (int i = 0; i <= n; i++) cout << G[i].color << " " << G[i].id << endl; cout << "-----" << endl;
	// for (int i = 0; i < n; i++) cout << D[i] << " " << C[i] << endl;

	return 0;
}


/*input
3 2 2
1 1 2
1 2
2 1
*/
#include <iostream>
#include <cstdio>
#include <vector>
#include <bitset>
#include <algorithm>

using namespace std;

const int MAXN = 200000 + 8;
struct Group {
	int color, id;
	Group() {}
	Group(int _c, int _i) { color = _c, id = _i; }
	bool operator == (Group x) {
		return (x.id == id and x.color == color);
	}
};
int compare_group(Group a, Group b) {
	if (a.id < b.id) return -1;
	return 1;
}

int n, m, k, x, y;
Group G[MAXN];
int C[MAXN], D[MAXN];
vector<int> linked[MAXN];
bitset<MAXN> mark;

void find_component(int x, int id) {
	C[id]++;
	mark[x] = 1;
	G[x].id = id;
	// cout << x << " " << mark[x] << " " << id << endl;
	for (int i = 0; i < linked[x].size(); i++) {
		// cout << "NEXT is " << linked[x][i] << " where mark is " << mark[linked[x][i]] << endl;
		if (mark[linked[x][i]] == 0)
			find_component(linked[x][i], id);
	}
}

int main() {

	scanf("%d %d %d", &n, &m, &k);
	for (int i = 0; i < n; i++) {
		scanf("%d", &x);
		G[i].color = x;
	}
	for (int i = 0; i < m; i++) {
		scanf("%d %d", &x, &y);
		x--; y--;
		linked[x].push_back(y);
		linked[y].push_back(x);
	}

	mark = 0;
	int counter = 0;
	for (int i = 0; i < n; i++)
		if (mark[i] == 0) { find_component(i, ++counter); }

	sort(G, G + n, compare_group);
	// for (int i = 0; i < n; i++) cout <<
	// for (int i = 0; i < n; i++) cout << G[i].color << " " << G[i].id << endl;
	G[n] = Group(MAXN, MAXN);
	int a, b = 0;
	while (a < n) {
		b = a + 1;
		while (G[b] == G[a]) b++;
		D[G[a].id] = max(D[G[a].id], b - a);
		a = b;
	}
	int res = 0;
	for (int i = 0; i < n; i++) res += C[i] - D[i];
	printf("%d\n", res);

	// for (int i = 0; i < n; i++) cout << D[i] << " " << C[i] << endl;

	return 0;
}


/*input
10 3 2
2 1 1 2 1 1 2 1 2 2
4 10
9 3
5 7
*/
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

const int MAXN = 200000 + 8;
struct Group {
	int color, id;
	Group() {}
	Group(int _c, int _i) { color = _c, id = _i; }
	bool operator == (Group x) { return (x.id == id and x.color == color); }
};
int compare_group(Group a, Group b) {
	if (a.id < b.id) return 1;
	return 0;
}

int n, m, k, x, y;
Group G[MAXN];
int C[MAXN], D[MAXN];
vector<int> linked[MAXN];
bool mark[MAXN];

void find_component(int x, int id) {
	C[id]++;
	mark[x] = 1;
	G[x].id = id;
	for (int i = 0; i < linked[x].size(); i++)
		if (mark[linked[x][i]] == 0)
			find_component(linked[x][i], id);
}

int main() {

	for (int i = 0; i < MAXN; i++) {
		D[i] = C[i] = 0;
		mark[i] = 0;

	}

	scanf("%d %d %d", &n, &m, &k);
	for (int i = 0; i < n; i++) {
		scanf("%d", &x);
		G[i].color = x;
	}
	for (int i = 0; i < m; i++) {
		scanf("%d %d", &x, &y);
		x--; y--;
		linked[x].push_back(y);
		linked[y].push_back(x);
	}

	int counter = 0;
	for (int i = 0; i < n; i++)
		if (mark[i] == 0) find_component(i, ++counter);

	G[n] = Group(MAXN, MAXN);
	sort(G, G + n, compare_group);
	int a, b = 0;
	while (a < n) {
		b = a + 1;
		while (G[b] == G[a]) b++;
		D[G[a].id] = max(D[G[a].id], b - a);
		a = b;
	}
	int res = 0;
	for (int i = 0; i < n; i++) res += C[i] - D[i];
	printf("%d\n", res);

	// for (int i = 0; i < n; i++) cout << G[i].color << " " << G[i].id << endl; cout << "-----" << endl;
	// for (int i = 0; i < n; i++) cout << D[i] << " "; cout << endl;
	// for (int i = 0; i < n; i++) cout << C[i] << " "; cout << endl;

	return 0;
}


/*input
8 11 8
1 1 3 4 5 6 1 1
1 8
1 2
2 8
8 7
6 5
5 4
3 4
8 7
8 7
8 7
6 7
*/
#include <iostream>
#include <cstdio>
#include <vector>
#include <bitset>
#include <algorithm>

using namespace std;

const int MAXN = 200000 + 8;
struct Group {
	int color, id;
	Group() {}
	Group(int _c, int _i) { color = _c, id = _i; }
	bool operator == (Group x) {
		return (x.id == id and x.color == color);
	}
};
int compare_group(Group a, Group b) {
	if (a.id < b.id) return -1;
	if (a.id == b.id) {
		if (a.color < b.color) return -1;
		if (a.color > b.color) return 1;
		return 0;
	}
	return 1;
}

int n, m, k, x, y;
Group G[MAXN];
int C[MAXN], D[MAXN];
vector<int> linked[MAXN];
bitset<MAXN> mark;

void find_component(int x, int id) {
	C[id]++;
	mark[x] = 1;
	G[x].id = id;
	for (int i = 0; i < linked[x].size(); i++)
		if (mark[linked[x][i]] == 0)
			find_component(linked[x][i], id);
}

int main() {

	scanf("%d %d %d", &n, &m, &k);
	for (int i = 0; i < n; i++) {
		scanf("%d", &x);
		G[i].color = x;
	}
	for (int i = 0; i < m; i++) {
		scanf("%d %d", &x, &y);
		x--; y--;
		linked[x].push_back(y);
		linked[y].push_back(x);
	}

	mark = 0;
	int counter = 0;
	for (int i = 0; i < n; i++)
		if (mark[i] == 0) find_component(i, ++counter);
	sort(G, G + n, compare_group);

	G[n] = Group(MAXN, MAXN);
	int a, b = 0;
	while (a < n) {
		b = a + 1;
		while (G[b] == G[a]) b++;
		D[G[a].id] = max(D[G[a].id], b - a);
		a = b;
	}
	int res = 0;
	for (int i = 0; i < n; i++) res += C[i] - D[i];
	printf("%d\n", res);

	// for (int i = 0; i <= n; i++) cout << G[i].color << " " << G[i].id << endl; cout << "-----" << endl;
	// for (int i = 0; i < n; i++) cout << D[i] << " " << C[i] << endl;

	return 0;
}


/*input
10 3 2
2 1 1 2 1 1 2 1 2 2
4 10
9 3
5 7
*/
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

const int MAXN = 200000 + 8;
struct Group {
	int color, id;
	Group() {}
	Group(int _c, int _i) { color = _c, id = _i; }
	bool operator == (Group x) { return (x.id == id and x.color == color); }
};
int compare_group(Group a, Group b) {
	if (a.id < b.id) return -1;
	if (a.id == b.id) {
		if (a.color < b.color) return -1;
		if (a.color > b.color) return 1;
		return 0;
	}
	return 1;
}

int n, m, k, x, y;
Group G[MAXN];
int C[MAXN], D[MAXN];
vector<int> linked[MAXN];
bitset<MAXN> mark;

void find_component(int x, int id) {
	C[id]++;
	mark[x] = 1;
	G[x].id = id;
	for (int i = 0; i < linked[x].size(); i++)
		if (mark[linked[x][i]] == 0)
			find_component(linked[x][i], id);
}

int main() {

	scanf("%d %d %d", &n, &m, &k);
	for (int i = 0; i < n; i++) {
		scanf("%d", &x);
		G[i].color = x;
	}
	for (int i = 0; i < m; i++) {
		scanf("%d %d", &x, &y);
		x--; y--;
		linked[x].push_back(y);
		linked[y].push_back(x);
	}

	mark = 0;
	int counter = 0;
	for (int i = 0; i < n; i++)
		if (mark[i] == 0) find_component(i, ++counter);
	sort(G, G + n, compare_group);

	G[n] = Group(MAXN, MAXN);
	int a, b = 0;
	while (a < n) {
		b = a + 1;
		while (G[b] == G[a]) b++;
		D[G[a].id] = max(D[G[a].id], b - a);
		a = b;
	}
	int res = 0;
	for (int i = 0; i < n; i++) res += C[i] - D[i];
	printf("%d\n", res);

	// for (int i = 0; i <= n; i++) cout << G[i].color << " " << G[i].id << endl; cout << "-----" << endl;
	// for (int i = 0; i < n; i++) cout << D[i] << " " << C[i] << endl;

	return 0;
}


/*input
3 2 3
1 2 3
1 2
2 3
*/
#include <iostream>
#include <cstdio>
#include <vector>
#include <bitset>
#include <algorithm>

#define pb push_back
#define mp make_pair

using namespace std;

const int MAXN = 200000 + 8;

int n, m, k, cnt = 0, x, y;
int C[MAXN], P[MAXN];
vector<int> A[MAXN];
vector<int> B[MAXN];
bitset<MAXN> visited;

void dfs (int v, int num) {
    B[num].pb(C[v]);
    visited[v] = 1;
    for (int i = 0; i < A[v].size(); i++)
        if (visited[A[v][i]] == 0)
            dfs(A[v][i], num);
}

int count_colors (vector<int> V) {
    if (V.size() < 2) return 0;
    int tmp = V.size();
    sort(V.begin(), V.end());
    V.pb(-1);
    int x = 0, y = 0, z = 0;
    while (x < V.size()) {
        while (V[y] == V[x]) y++;
        z = max(z, y - x);
        x = y;
    }
    return tmp - z;
}

int main () {

    for (int i = 0; i < n; i++) P[i] = -1;
    visited = 0;

    scanf("%d %d %d", &n, &m, &k);
    for (int i = 0; i < n; i++) scanf("%d", &C[i]);
    for (int i = 0; i < m; i++) {
        scanf("%d %d", &x, &y);
        x--; y--;
        A[x].pb(y);
        A[y].pb(x);
        // cout << x << " " << y << " " << used[x] << " " << used[y] << endl;
    }
    for (int i = 0; i < n; i++)
        if (visited[i] == 0)
            dfs(i, cnt++);

    int res = 0;
    for (int i = 0; i < cnt; i++) res += count_colors(B[i]);
    cout << res << endl;

    return 0;
}


/*input
10 3 2
2 1 1 2 1 1 2 1 2 2
4 10
9 3
5 7
*/
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

const int MAXN = 200000 + 8;
struct Group {
	int color, id;
	Group() {}
	Group(int _c, int _i) { color = _c, id = _i; }
	bool operator == (Group x) { return (x.id == id and x.color == color); }
};
int compare_group(Group a, Group b) {
	if (a.id < b.id) return -1;
	if (a.id == b.id) {
		if (a.color < b.color) return -1;
		if (a.color > b.color) return 1;
		return 0;
	}
	return 1;
}

int n, m, k, x, y;
Group G[MAXN];
int C[MAXN], D[MAXN];
vector<int> linked[MAXN];
bool mark[MAXN];

void find_component(int x, int id) {
	C[id]++;
	mark[x] = 1;
	G[x].id = id;
	for (int i = 0; i < linked[x].size(); i++)
		if (mark[linked[x][i]] == 0)
			find_component(linked[x][i], id);
}

int main() {

	scanf("%d %d %d", &n, &m, &k);
	for (int i = 0; i < n; i++) {
		scanf("%d", &x);
		G[i].color = x;
	}
	for (int i = 0; i < m; i++) {
		scanf("%d %d", &x, &y);
		x--; y--;
		linked[x].push_back(y);
		linked[y].push_back(x);
	}

	for (int i = 0; i < n; i++) mark[i] = 0;
	int counter = 0;
	for (int i = 0; i < n; i++)
		if (mark[i] == 0) find_component(i, ++counter);
	sort(G, G + n, compare_group);

	G[n] = Group(MAXN, MAXN);
	int a, b = 0;
	while (a < n) {
		b = a + 1;
		while (G[b] == G[a]) b++;
		D[G[a].id] = max(D[G[a].id], b - a);
		a = b;
	}
	int res = 0;
	for (int i = 0; i < n; i++) res += C[i] - D[i];
	printf("%d\n", res);

	// for (int i = 0; i <= n; i++) cout << G[i].color << " " << G[i].id << endl; cout << "-----" << endl;
	// for (int i = 0; i < n; i++) cout << D[i] << " " << C[i] << endl;

	return 0;
}


/*input
4 3 2
1 1 2 2
1 2
3 4
2 3
*/
#include <iostream>
#include <cstdio>
#include <vector>
#include <bitset>
#include <algorithm>

#define pb push_back
#define mp make_pair

using namespace std;

const int MAXN = 200000 + 8;

int n, m, k, cnt = 0, x, y;
int C[MAXN], P[MAXN];
vector<int> A[MAXN];

void dfs (int x, int num) {
    P[x] = num;
    for (int i = 0; i < A[x].size(); i++) {
        int y = A[x][i];
        if (P[y] == 0) dfs(y, num);
    }
}

int count_colors (vector<int> V) {
    int tmp = V.size();
    sort(V.begin(), V.end());
    V.pb(-1);
    int x = 0, y = 0, z = 0;
    while (x < V.size()) {
        while (V[y] == V[x]) y++;
        z = max(z, y - x);
        x = y;
    }
    return tmp - z;
}

int main () {

    for (int i = 0; i < n; i++) P[i] = -1;

    scanf("%d %d %d", &n, &m, &k);
    for (int i = 0; i < n; i++) scanf("%d", &C[i]);
    for (int i = 0; i < m; i++) {
        scanf("%d %d", &x, &y);
        x--; y--;
        A[x].pb(y);
        A[y].pb(x);
        P[x] = P[y] = 0;
        // cout << x << " " << y << " " << used[x] << " " << used[y] << endl;
    }
    for (int i = 0; i < n; i++) {
        if (P[i] == 0) dfs(i, ++cnt);
    }

    for (int i = 0; i <= cnt; i++) A[i].clear();
    for (int i = 0; i < n; i++) A[P[i]].pb(C[i]);

    int res = 0;
    for (int i = 1; i <= cnt; i++) res += count_colors(A[i]);
    cout << res << endl;

    return 0;
}


/*input
10 3 2
2 1 1 2 1 1 2 1 2 2
4 10
9 3
5 7
*/
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

const int MAXN = 200000 + 8;
struct Group {
	int color, id;
	Group() {}
	Group(int _c, int _i) { color = _c, id = _i; }
	bool operator == (Group x) { return (x.id == id and x.color == color); }
};
int compare_group(Group a, Group b) {
	if (a.id < b.id) return 1;
	if (a.id == b.id) {
		if (a.color < b.color) return 1;
		return 0;
	}
	return 0;
}

int n, m, k, x, y;
Group G[MAXN];
int C[MAXN], D[MAXN];
vector<int> linked[MAXN];
bool mark[MAXN];

void find_component(int x, int id) {
	C[id]++;
	mark[x] = 1;
	G[x].id = id;
	for (int i = 0; i < linked[x].size(); i++)
		if (mark[linked[x][i]] == 0)
			find_component(linked[x][i], id);
}

int main() {

	for (int i = 0; i < MAXN; i++) {
		D[i] = C[i] = 0;
		mark[i] = 0;

	}

	scanf("%d %d %d", &n, &m, &k);
	for (int i = 0; i < n; i++) {
		scanf("%d", &x);
		G[i].color = x;
	}
	for (int i = 0; i < m; i++) {
		scanf("%d %d", &x, &y);
		x--; y--;
		linked[x].push_back(y);
		linked[y].push_back(x);
	}

	int counter = 0;
	for (int i = 0; i < n; i++)
		if (mark[i] == 0) find_component(i, ++counter);

	G[n] = Group(MAXN, MAXN);
	sort(G, G + n, compare_group);
	int a, b = 0;
	while (a < n) {
		b = a + 1;
		while (G[b] == G[a]) b++;
		D[G[a].id] = max(D[G[a].id], b - a);
		a = b;
	}
	int res = 0;
	for (int i = 0; i < n; i++) res += C[i] - D[i];
	printf("%d\n", res);

	// for (int i = 0; i < n; i++) cout << G[i].color << " " << G[i].id << endl; cout << "-----" << endl;
	// for (int i = 0; i < n; i++) cout << D[i] << " "; cout << endl;
	// for (int i = 0; i < n; i++) cout << C[i] << " "; cout << endl;

	return 0;
}


/*input
3 2 2
1 1 2
1 2
2 1
*/
#include <iostream>
#include <cstdio>
#include <vector>
#include <bitset>

#define pb push_back
#define mp make_pair

using namespace std;

const int MAXN = 200000 + 8;

int n, m, k, cnt = 0, x, y;
int C[MAXN], P[MAXN];
vector<int> A[MAXN];
bitset<MAXN> mark;
bitset<MAXN> used;

void dfs(int x) {
    for (int i = 0; i < A[x].size(); i++) {
        int y = A[x][i];
        if (mark[y] == 0) {
            mark[y] = 1;
            P[y] = P[x];
            dfs(y);
        }
    }
}

int max_colors (vector<int> V) {
    V.pb(-1);
    int x = 0, y = 0, z = 0;
    while (x < V.size()) {
        while (V[y] == V[x]) y++;
        z = max(z, y - x);
        x = y;
    }
    return z;
}

int main () {

    used = 0;
    mark = 0;

    scanf("%d %d %d", &n, &m, &k);
    for (int i = 0; i < n; i++) scanf("%d", &C[i]);
    for (int i = 0; i < m; i++) {
        scanf("%d %d", &x, &y);
        x--; y--;
        A[x].pb(y);
        A[y].pb(x);
        used[x] = 1; used[y] = 1;
        // cout << x << " " << y << " " << used[x] << " " << used[y] << endl;
    }
    for (int i = 0; i < n; i++) {
        if (used[i] && P[i] == 0) {
            P[i] = ++cnt;
            dfs(i);
        }
    }

    for (int i = 0; i <= cnt; i++) A[i].clear();
    for (int i = 0; i < n; i++) A[P[i]].pb(C[i]);

    int res = 0;
    for (int i = 1; i <= cnt; i++) {
        res += A[i].size() - max_colors(A[i]);
    }
    cout << res << endl;
    return 0;
}


/*input
3 2 3
1 2 3
1 2
2 3
*/
#include <iostream>
#include <cstdio>
#include <vector>
#include <bitset>
#include <algorithm>

#define pb push_back
#define mp make_pair

using namespace std;

const int MAXN = 200000 + 8;

int n, m, k, cnt = 0, x, y;
int C[MAXN];
vector<int> A[MAXN];
vector<int> B[MAXN];
bool visited[MAXN];

void dfs (int v, int num) {
    B[num].pb(C[v]);
    visited[v] = true;
    for (int i = 0; i < A[v].size(); i++)
        if (!visited[A[v][i]])
            dfs(A[v][i], num);
}

int count_colors (vector<int> V) {
    if (V.size() < 2) return 0;
    int tmp = V.size();
    sort(V.begin(), V.end());
    V.pb(-1);
    int x = 0, y = 0, z = 0;
    while (x < V.size()) {
        while (V[y] == V[x]) y++;
        z = max(z, y - x);
        x = y;
    }
    return tmp - z;
}

int main () {

    for (int i = 0; i < n; i++) visited[i] = false;

    scanf("%d %d %d", &n, &m, &k);
    for (int i = 0; i < n; i++) scanf("%d", &C[i]);
    for (int i = 0; i < m; i++) {
        scanf("%d %d", &x, &y);
        x--; y--;
        A[x].pb(y);
        A[y].pb(x);
    }
    for (int i = 0; i < n; i++)
        if (!visited[i])
            dfs(i, cnt++);

    int res = 0;
    for (int i = 0; i < cnt; i++) res += count_colors(B[i]);
    cout << res << endl;

    return 0;
}


/*input
3 2 2
1 1 2
1 2
2 1
*/
#include <iostream>
#include <cstdio>
#include <vector>
#include <bitset>

using namespace std;

const int MAXN = 200000 + 8;
struct Group {
	int color, id;
	Group() {}
	Group(int _c, int _i) { color = _c, id = _i; }
	bool operator == (Group x) {
		return (x.id == id and x.color == color);
	}
};
int compare_group(Group a, Group b) {
	if (a.id < b.id) return -1;
	return 1;
}

int n, m, k, x, y;
Group G[MAXN];
int C[MAXN], D[MAXN];
vector<int> linked[MAXN];
bitset<MAXN> mark;

void find_component(int x, int id) {
	C[id]++;
	mark[x] = 1;
	G[x].id = id;
	// cout << x << " " << mark[x] << " " << id << endl;
	for (int i = 0; i < linked[x].size(); i++) {
		// cout << "NEXT is " << linked[x][i] << " where mark is " << mark[linked[x][i]] << endl;
		if (mark[linked[x][i]] == 0)
			find_component(linked[x][i], id);
	}
}

int main() {

	scanf("%d %d %d", &n, &m, &k);
	for (int i = 0; i < n; i++) {
		scanf("%d", &x);
		G[i].color = x;
	}
	for (int i = 0; i < m; i++) {
		scanf("%d %d", &x, &y);
		x--; y--;
		linked[x].push_back(y);
		linked[y].push_back(x);
	}

	mark = 0;
	int counter = 0;
	for (int i = 0; i < n; i++)
		if (mark[i] == 0) { find_component(i, ++counter); }

	sort(G, G + n, compare_group);
	// for (int i = 0; i < n; i++) cout <<
	// for (int i = 0; i < n; i++) cout << G[i].color << " " << G[i].id << endl;
	G[n] = Group(MAXN, MAXN);
	int a, b = 0;
	while (a < n) {
		b = a + 1;
		while (G[b] == G[a]) b++;
		D[G[a].id] = max(D[G[a].id], b - a);
		a = b;
	}
	int res = 0;
	for (int i = 0; i < n; i++) res += C[i] - D[i];
	printf("%d\n", res);

	// for (int i = 0; i < n; i++) cout << D[i] << " " << C[i] << endl;

	return 0;
}


/*input
3 2 3
1 2 3
1 2
2 3
*/
#include <iostream>
#include <cstdio>
#include <vector>
#include <bitset>
#include <algorithm>

#define pb push_back
#define mp make_pair

using namespace std;

const int MAXN = 200000 + 8;

int n, m, k, cnt = 0, x, y;
int C[MAXN], P[MAXN];
vector<int> A[MAXN];
vector<int> B[MAXN];
bitset<MAXN> visited;

void dfs (int v, int num) {
    B[num].pb(C[v]);
    visited[v] = 1;
    for (int i = 0; i < A[v].size(); i++)
        if (!visited[A[v][i]])
            dfs(A[v][i], num);
}

int count_colors (vector<int> V) {
    if (V.size() < 2) return 0;
    int tmp = V.size();
    sort(V.begin(), V.end());
    V.pb(-1);
    int x = 0, y = 0, z = 0;
    while (x < V.size()) {
        while (V[y] == V[x]) y++;
        z = max(z, y - x);
        x = y;
    }
    return tmp - z;
}

int main () {

    for (int i = 0; i < n; i++) P[i] = -1;

    scanf("%d %d %d", &n, &m, &k);
    for (int i = 0; i < n; i++) scanf("%d", &C[i]);
    for (int i = 0; i < m; i++) {
        scanf("%d %d", &x, &y);
        x--; y--;
        A[x].pb(y);
        A[y].pb(x);
        // cout << x << " " << y << " " << used[x] << " " << used[y] << endl;
    }
    for (int i = 0; i < n; i++)
        if (!visited[i])
            dfs(i, cnt++);

    int res = 0;
    for (int i = 0; i < cnt; i++) res += count_colors(B[i]);
    cout << res << endl;

    return 0;
}


/*
   Author:fanmeng
   Lang:C++
   PROB:ohha
*/
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <vector>
#include <set>

using namespace std;

int fa[200005];
map<int,int>mp[200005];
int n,m,k;
int color[200005];
int tol;

int found(int x) {
    return x==fa[x]?x:fa[x]=found(fa[x]);
}

int main() {
    cin >> n >> m >> k;
    for(int i = 1; i <= n; i++) {
        cin >> color[i];
        fa[i] = i;
    }
    int a,b;
    tol = 0;
    while(m--) {
        cin >> a >> b;
        a = found(a);
        b = found(b);
        fa[max(a,b)] = min(a,b);
    }
    for(int i = 1;i <= n;i++){
        mp[found(i)][color[i]]++;
    }
    for(int i = 1;i<=n;i++){
        int s = 0;
        int mx = 0;
        for(map<int,int>::iterator it = mp[i].begin();it !=mp[i].end();it++){
            s += it->second;
            mx = max(mx,it->second);
        }
        tol += s-mx;
    }
    cout << tol << endl;
    return 0;
}


/*
   Author:fanmeng
   Lang:C++
   PROB:ohha
*/
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <vector>
#include <set>

using namespace std;

int a[200005];
int n,m,k;
vector<int>v[200005];

bool cmp(vector<int>x,vector<int>y){
    return x.size() > y.size();
}
int tol;
struct point {
    int x;
}p;
int s;

void bfs(int xx){
    queue<point>q;
    p.x = xx;
    q.push(p);
    while(!q.empty()){
        p = q.front();
        q.pop();
        //cout << v[p.x].size() << endl;
        for(int i = 0;i < (int)v[p.x].size();i++){
            point pp = p;
            int t = v[p.x][i];
            if(a[pp.x] != a[t]){
                a[t] = a[pp.x];
                pp.x = t;
                tol++;
                q.push(pp);
            }
        }
        v[p.x].clear();

    }
}

int main() {
    cin >> n >> m >> k;
    for(int i = 1;i <= n;i++){
        cin >> a[i];
    }
    int b,c;
    while(m--){
        cin >> b >> c;
        v[b].push_back(c);
        v[c].push_back(b);
    }
    tol = 0;

    for(int i = 1;i <= n;i++){
        if(v[i].size() != 0){
            bfs(i);
        }
    }
    cout << tol << endl;
    return 0;
}


/*
   Author:fanmeng
   Lang:C++
   PROB:ohha
*/
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <vector>
#include <set>

using namespace std;

int fa[200005];
int childnum[200005];
int n,m,k;
int color[200005];

int found(int x) {
    return x==fa[x]?x:found(fa[x]);
}
void bing(int x,int y) {
    x = found(x);
    y = found(y);
    if(x > y) {
        swap(x,y);
    }
    if(x != y) {
        fa[y] = x;
        childnum[x] += childnum[y];
    }
}
int main() {
    cin >> n >> m >> k;
    for(int i = 1; i <= k; i++) {
        fa[i] =i;
        childnum[i] = 1;
    }
    for(int i = 1;i <= n;i++){
        cin >> color[i];
    }
    int a,b;
    while(m--){
        cin >> a >> b;
        bing(color[a],color[b]);
    }
    int tol = 0;
    for(int i = 1;i<= k;i++){
        if(fa[i] == i){
            tol += childnum[i]-1;
        }
    }
    cout << tol << endl;
    return 0;
}


/*
   Author:fanmeng
   Lang:C++
   PROB:ohha
*/
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <vector>
#include <set>

using namespace std;

int a[200005];
int n,m,k;
vector<int>v[200005];
struct tol{
    int x;
    int num;
    bool operator < (const tol &y) const {
       return num > y.num;
    }
}st[200005];

int tol;
struct point {
    int x;
}p;
int s;

void bfs(int xx){
    queue<point>q;
    p.x = xx;
    q.push(p);
    while(!q.empty()){
        p = q.front();
        q.pop();
        //cout << v[p.x].size() << endl;
        for(int i = 0;i < (int)v[p.x].size();i++){
            point pp = p;
            int t = v[p.x][i];
            if(a[pp.x] != a[t]){
                a[t] = a[pp.x];
                pp.x = t;
                tol++;
                q.push(pp);
            }
        }
        v[p.x].clear();

    }
}

int main() {
    cin >> n >> m >> k;
    for(int i = 1;i <= n;i++){
        cin >> a[i];
        st[i].x = i;
    }
    int b,c;
    while(m--){
        cin >> b >> c;
        st[b].num++;
        st[c].num++;
        v[b].push_back(c);
        v[c].push_back(b);
    }
    tol = 0;
    sort(st,st+n);
    for(int i = 0;i <= n;i++){
        if(v[st[i].x].size() != 0){
            bfs(st[i].x);
        }
    }
    cout << tol << endl;
    return 0;
}


/*
   Author:fanmeng
   Lang:C++
   PROB:ohha
*/
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <vector>
#include <set>

using namespace std;

int a[200005];
int n,m,k;
vector<int>v[200005];
struct tol {
    int x;
    int num;
    bool operator < (const tol &y) const {
        return num > y.num;
    }
} st[200005];

int tol;
struct point {
    int x;
} p;
int s;

void bfs(int xx) {
    queue<point>q;
    p.x = xx;
    q.push(p);
    while(!q.empty()) {
        p = q.front();
        q.pop();
        //cout << v[p.x].size() << endl;
        for(int i = 0; i < (int)v[p.x].size(); i++) {
            point pp = p;
            int t = v[p.x][i];
            if(a[pp.x] != a[t]) {
                a[t] = a[pp.x];
                pp.x = t;
                tol++;
                q.push(pp);
            }
        }
        v[p.x].clear();

    }
}

int main() {
    cin >> n >> m >> k;
    for(int i = 1; i <= n; i++) {
        cin >> a[i];
        st[i].x = i;
    }
    int b,c;
    while(m--) {
        cin >> b >> c;
        st[b].num++;
        st[c].num++;
        v[b].push_back(c);
        v[c].push_back(b);
    }
    tol = 0;
    sort(st,st+n);
    for(int i = 0; i <= n; i++) {
        if(st[i].num == 0) {
            break;
        }
        bfs(st[i].x);
    }
    cout << tol << endl;
    return 0;
}


/*
   Author:fanmeng
   Lang:C++
   PROB:ohha
*/
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <vector>
#include <set>

using namespace std;

int a[200005];
int n,m,k;
vector<int>v[200005];
struct tol {
    int x;
    int num;
    bool operator < (const tol &y) const {
        return num > y.num;
    }
} st[200005];

int tol;
struct point {
    int x;
} p;
int s;

void bfs(int xx) {
    queue<point>q;
    p.x = xx;
    q.push(p);
    while(!q.empty()) {
        p = q.front();
        q.pop();
        //cout << v[p.x].size() << endl;
        for(int i = 0; i < (int)v[p.x].size(); i++) {
            point pp = p;
            int t = v[p.x][i];
            v[t].clear();
            if(a[pp.x] != a[t]) {
                a[t] = a[pp.x];
                pp.x = t;
                tol++;
                q.push(pp);
            }
        }
        v[p.x].clear();
    }
}

int main() {
    cin >> n >> m >> k;
    for(int i = 1; i <= n; i++) {
        cin >> a[i];
        st[i].x = i;
    }
    int b,c;
    while(m--) {
        cin >> b >> c;
        st[b].num++;
        st[c].num++;
        v[b].push_back(c);
        v[c].push_back(b);
    }
    tol = 0;
    sort(st,st+n);
    for(int i = 0; i <= n; i++) {
        if(st[i].num == 0) {
            break;
        }
        bfs(st[i].x);
    }
    cout << tol << endl;
    return 0;
}


/*
   Author:fanmeng
   Lang:C++
   PROB:ohha
*/
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <vector>
#include <set>

using namespace std;

int fa[200005];
int childnum[200005];
int n,m,k;
int color[200005];
int tol;

int found(int x) {
    return x==fa[x]?x:found(fa[x]);
}

void bing(int x,int y) {
    x = found(x);
    y = found(y);
    if(color[x] != color[y]) {
        tol++;
        if(x != y) {
            fa[y] = x;
        }
    }
}
int main() {
    cin >> n >> m >> k;
    for(int i = 1; i <= n; i++) {
        fa[i] = i;
        childnum[i] = 0;
    }
    for(int i = 1; i <= n; i++) {
        cin >> color[i];
    }
    int a,b;
    tol = 0;
    while(m--) {
        cin >> a >> b;
        bing(a,b);
    }
    cout << tol << endl;
    return 0;
}


/*
   Author:fanmeng
   Lang:C++
   PROB:ohha
*/
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <vector>
#include <set>

using namespace std;

int a[200005];
int n,m,k;
vector<int>v[200005];

bool cmp(vector<int>x,vector<int>y){
    return x.size() > y.size();
}
int tol;
struct point {
    int x;
}p;
int s;

void bfs(){
    queue<point>q;
    p.x = s;
    q.push(p);
    while(!q.empty()){
        p = q.front();
        q.pop();
        //cout << v[p.x].size() << endl;
        for(int i = 0;i < (int)v[p.x].size();i++){
            point pp = p;
            int t = v[p.x][i];
            if(a[pp.x] != a[t]){
                a[t] = a[pp.x];
                pp.x = t;
                tol++;
                q.push(pp);
            }
        }
    }
}

int main() {
    cin >> n >> m >> k;
    for(int i = 1;i <= n;i++){
        cin >> a[i];
    }
    int b,c;
    int index =0;
    s = 0;
    while(m--){
        cin >> b >> c;
        v[b].push_back(c);
        v[c].push_back(b);
        if(v[b].size() > index){
            s = b;
            index = v[b].size();
        }
        if(v[c].size() > index){
            s = c;
            index = v[c].size();
        }
    }
    tol = 0;
    bfs();
    cout << tol << endl;
    return 0;
}


#include <iostream>
#include <map>
#include <vector>
#include <cstdio>

using namespace std;

int socks[200100],father[200100];
vector<int> type[200100];

int findit(int k)
{
    int temp=k;
    while(k!=father[k]){
        k=father[k];
    }
    while(temp!=father[temp]){
        int t=father[temp];
        father[temp]=k;
        temp=t;
    }
    return k;
}

int main()
{
    int n,m,k;
    while(cin>>n>>m>>k){
        int i,j;
        for(i=1;i<=n;i++){
            scanf("%d",&socks[i]);
            father[i]=i;
        }
        for(i=1;i<=m;i++){
            int a,b;
            scanf("%d%d",&a,&b);
            int p1=findit(a);
            int p2=findit(b);
            if(p1==p2)continue;
            father[p1]=father[p2];
        }
        for(i=1;i<=n;i++){
            int anc=findit(i);
            type[anc].push_back(i);
        }
        int ans=0;
        for(i=1;i<=n;i++){
            map<int,int> dif;
            int tot=0,maxi=0;
            for(j=0;j<type[i].size();j++){
                int pos=type[i][j];
                dif[socks[pos]]++;
            }
            for(map<int,int>::iterator it=dif.begin();it!=dif.end();it++){
                if(it->second>maxi)
                    maxi=it->second;
                tot+=it->second;
            }
            ans+=tot-maxi;
        }
        cout<<ans<<endl;
    }
    return 0;
}


#include<iostream>
#include<vector>
#include<cstring>
#include<cmath>
#include<map>
using namespace std;
#define N 200010

vector<int > sock[N];

int parent[N],col[N],num[N];
int tol;
void init(int n)
{
	for(int i=0;i<=n;i++)
	parent[i]=i;
}
int find(int x)
{
	if(parent[x]==x)
	return x;
	else
	{
		parent[x]=find(parent[x]);
		return parent[x];
	}

}

void unite(int x,int y)
{
	x=find(x);
	y=find(y);
	if(x!=y)
	parent[y]=x;
}

int main()
{
	int n,m,k,l,r;
	cin>>n>>m>>k;
	for(int i=1;i<=n;i++)
	{
		cin>>col[i];
	}
	init(n);
	for(int i=1;i<=m;i++)
	{
		cin>>l>>r;
		unite(l,r);
	}

	for(int i=1;i<=n;i++)
	{
		if(parent[i]==i)
			num[i]=++tol;
	}
	for(int i=1;i<=n;i++)
	{
		sock[num[find(i)]].push_back(col[i]);
	}
	int res=0;
	for(int i=1;i<=tol;i++)
	{
		int size=sock[i].size();
		int maxx=0;
		map<int ,int> mp;
		for(int j=0;j<size-1;j++)
		{
			mp[sock[i][j]]++;
			maxx=max(maxx,mp[sock[i][j]]);
		}
		res+=(size-maxx);
	}
	cout<<res<<endl;
	return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define INF 1e9
#define ms(a,val) memset((a),(val),(sizeof(a)))
#pragma comment(linker, "/STACK:102400000,102400000")

using namespace std;

const int maxn=200005;
int color[maxn],vis[maxn],dfsvis[maxn],n,m,k;
map<int,int> cou;
vector<int> G[maxn];
int par[maxn];
int ranks[maxn];
void init(){
    for(int i=0;i<n;i++){
        par[i]=i;
        ranks[i]=0;
    }
}
int finds(int x){
    if(par[x]==x){
        return x;
    }else{
        return par[x]=finds(par[x]);
    }
}
void unite(int x,int y){
    x=finds(x);
    y=finds(y);
    if(x==y)return;
    if(ranks[x]<ranks[y]){
        par[x]=y;
    }
    else{
        par[y]=x;
        if(ranks[x]==ranks[y])ranks[x]++;
    }
}
bool same(int x,int y){
    return finds(x)==finds(y);
}
void dfs(int n){
    cou[color[n]]++;
    vis[n]=1;
    for(vector<int>::iterator it=G[n].begin();it!=G[n].end();it++){
        if(!vis[*it])dfs(*it);
    }
}
int main() {
    int l,r;
    while(~scanf("%d%d%d",&n,&m,&k)){
        int ans=0;
        ms(vis,0),ms(dfsvis,0);
        init();
        for(int i=0;i<n;i++)scanf("%d",&color[i]);
        for(int i=0;i<m;i++){
            scanf("%d%d",&l,&r);
            G[l-1].push_back(r-1),G[r-1].push_back(l-1);
            unite(l-1,r-1);
        }
        for(int i=0;i<n;i++){
            if(!dfsvis[finds(i)]){
                int all=0,maxs=-1;
                cou.clear();
                dfs(finds(i));
                for(map<int,int>::iterator it=cou.begin();it!=cou.end();it++){
                    all+=it->second;
                    maxs=max(maxs,it->second);
                }
                ans+=all-maxs;
                dfsvis[finds(i)]=1;
            }
        }
        printf("%d\n",ans);
    }
	return 0;
}


#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
int n, m, k;
vector<int> color;
vector<int> par;
vector<int> rak;
struct ClrCot
{
	map<int, int> clrCot;
	int maxn;
	int ssize;
};
map<int, ClrCot> sockSet;
int find(int x)
{
	if (par[x] == x)
		return x;
	else {
		return par[x] = find(par[x]);
	}
}
void unite(int i, int j)
{
	i = find(i);
	j = find(j);
	if (i == j)
		return;

	if (rak[i]<rak[j])
		par[i] = j;
	else
	{
		par[j] = i;
		if (rak[i] == rak[j])
			rak[i]++;
	}
}
int main()
{
	cin >> n >> m >> k;
	for (int i = 0; i < n; i++)
	{
		int c; cin >> c;
		color.push_back(c);
		par.push_back(i);
		rak.push_back(0);
	}

	for (int i = 0; i < m; i++)
	{
		int cl, cr;
		cin >> cl >> cr;
		cl--; cr--;
		unite(cl, cr);
	}

	for (int i = 0; i < n; i++)
	{
		ClrCot &ths = sockSet[find(i)];
		ths.clrCot[color[i]]++;
		ths.maxn = max(ths.maxn, ths.clrCot[color[i]]);
		ths.ssize++;
	}

	int cnt = 0;
	map<int, ClrCot>::iterator it = sockSet.begin();
	for (; it!=sockSet.end(); it++)
	{
		ClrCot &ths = it->second;
		cnt += ths.ssize - ths.maxn;
	}

	cout << cnt << endl;

	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>   //memset    string编译可以 但是会CE
#include <vector>
#include <map>
using namespace std;

int parent[200005];

int findRoot(int p)
{
    while(p != parent[p]){
        parent[p] = parent[parent[p]]; //cout<< p<<" - > "<<parent[parent[p]]<<endl;
        p = parent[p];
    }
    return p;
}
void unionn(int p1,int p2)
{

    int rp1 = findRoot(p1);
    int rp2 = findRoot(p2);//cout<<"root:" <<rp1<<" "<<rp2<<endl;
    if(rp1 != rp2){
       parent[rp1] = rp2;
    }
    return;
}

int col[200005];
vector<int> pile[200005];

int main()
{
   	int n,m,k;
    scanf("%d %d %d",&n,&m,&k);
    for(int i = 1; i<=n; i++)
    {
        scanf("%d",&col[i]);
    }

    int l,r;

	for(int i = 0; i<=n+10 ;i++){
        parent[i] = i;
    }

    for(int i = 1; i<=m; i++)
    {
        scanf("%d%d",&l,&r);
        unionn(l,r);
    	//cout<<"pil"<< findRoot(i) << "add" <<i<<"->"<< col[i]<<endl;
    }

    for(int i = 1; i<=n; i++)
    {
        pile[findRoot(i)].push_back(col[i]);
    }

	int ans = 0;

	for(int i = 1;i<n;i++){
		if((int)pile[i].size() > 1){

		  int maxC = -1;
        map<int,int> mp;
        mp.clear();
        for(int j = 0; j<pile[i].size(); j++)
        {
            mp[ pile[i][j] ] ++;
            maxC = max(maxC,mp[ pile[i][j] ]);
        }
        ans += pile[i].size() - maxC;
		}
	}
	printf("%d\n",ans);
    return 0;
}


#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <vector>

using namespace std;

int col[200005],f[200005];
vector<int> p[200005];

int Find(int x)
{
    if(f[x]==x)
        return f[x];
    else
        return f[x]=Find(f[x]);
}
void Unite(int a,int b)
{
    int x=Find(a);
    int y=Find(b);
    if(x!=y)
    {
        f[x]=y;
    }
}
int main()
{
    int n,m,k;
    scanf("%d%d%d",&n,&m,&k);
    for(int i=1; i<=n; i++)
    {
        scanf("%d",&col[i]);
        f[i]=i;
    }
    int l,r;
    for(int i=1; i<=m; i++)
    {
        scanf("%d%d",&l,&r);
        Unite(l,r);
    }
    for(int i=1; i<=n; i++)
    {
        p[Find(i)].push_back(col[i]);
    }
    int ans=0;
    for(int i=1; i<=n; i++)
    {
        if(p[i].size()<=1)
            continue;
        int MAX=-1;
        map<int,int> mp;
        mp.clear();
        for(int j=0; j<p[i].size(); j++)
        {
            mp[p[i][j]]++;
            MAX=max(MAX,mp[p[i][j]]);
        }
        //ans+=p[i].size()-MAX;
    }
    cout<<ans<<endl;
    return 0;
}


#include<vector>
#include<iostream>
#include<stdio.h>
#include<map>
using namespace std;
int a[200001],b[200001],s[200001];
vector<int> v[200000];
map<int,int> mp;
int max(int a,int b)
{
	return a>b?a:b;
}
int fd(int x)
{
    return a[x]==x?x:a[x]=fd(a[x]);
}
}
void wiyd(int x,int y)
{
	a[fd(x)]=fd(y);
}
int main()
{
	int n,m,k,i,j;
	scanf("%d%d%d",&n,&m,&k);
	for(i=1;i<=n;i++)
	{
		scanf("%d",&b[i]);
		a[i]=i;
	}
	for(i=1;i<=m;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		wiyd(x,y);
	}
	int sum=0,bj=0;
	for(i=1;i<=n;i++)
	{
		if(a[i]==i) s[i]=++bj;
	}
	for(i=1;i<=n;i++)
	{
		v[s[fd(i)]].push_back(b[i]);
	}
	for(i=1;i<=bj;i++)
	{
		int mx=0;
		k=v[i].size();
		mp.clear();
		for(j=0;j<=k-1;j++)
		{
			mp[v[i][j]]++;
			mx=max(mx,mp[v[i][j]]);
		}
		sum+=k-mx;
	}
	cout<<sum<<endl;
}


#include<vector>
#include<iostream>
#include<stdio.h>
#include<map>
using namespace std;
int a[200001],b[200001],s[200001];
vector<int> v[200001];
map<int,int> mp;
int max(int a,int b)
{
	return a>b?a:b;
}
int fd(int x)
{
    return a[x]==x?x:a[x]=fd(a[x]);
}
void wiyd(int x,int y)
{
	a[fd(x)]=fd(y);
}
int main()
{
	int n,m,k,i,j;
	scanf("%d%d%d",&n,&m,&k);
	for(i=1;i<=n;i++)
	{
		scanf("%d",&b[i]);
		a[i]=i;
	}
	for(i=1;i<=m;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		wiyd(x,y);
	}
	int sum=0,bj=0;
	for(i=1;i<=n;i++)
	{
		if(a[i]==i) s[i]=++bj;
	}
	for(i=1;i<=n;i++)
	{
		v[s[fd(i)]].push_back(b[i]);
	}
	for(i=1;i<=bj;i++)
	{
		int mx=0;
		k=v[i].size();
		mp.clear();
		for(j=0;j<=k-1;j++)
		{
			mp[v[i][j]]++;
			mx=max(mx,mp[v[i][j]]);
		}
		sum+=k-mx;
	}
	cout<<sum<<endl;
}


#include<vector>
#include<iostream>
#include<stdio.h>
#include<map>
using namespace std;
int a[200001],b[200001],s[200001];
vector<int> v[200000];
map<int,int> mp;
int max(int a,int b)
{
	return a>b?a:b;
}
int fd(int x)
{
    return a[x]==x?x:a[x]=fd(a[x]);
}
void wiyd(int x,int y)
{
	a[fd(x)]=fd(y);
}
int main()
{
	int n,m,k,i,j;
	scanf("%d%d%d",&n,&m,&k);
	for(i=1;i<=n;i++)
	{
		scanf("%d",&b[i]);
		a[i]=i;
	}
	for(i=1;i<=m;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		wiyd(x,y);
	}
	int sum=0,bj=0;
	for(i=1;i<=n;i++)
	{
		if(a[i]==i) s[i]=++bj;
	}
	for(i=1;i<=n;i++)
	{
		v[s[fd(i)]].push_back(b[i]);
	}
	for(i=1;i<=bj;i++)
	{
		int mx=0;
		k=v[i].size();
		mp.clear();
		for(j=0;j<=k-1;j++)
		{
			mp[v[i][j]]++;
			mx=max(mx,mp[v[i][j]]);
		}
		sum+=k-mx;
	}
	cout<<sum<<endl;
}


#include<vector>
#include<iostream>
#include<stdio.h>
#include<map>
using namespace std;
int a[200001],b[200001],s[200001];
vector<int> v[200000];
map<int,int> mp;
int max(int a,int b)
{
	return a>b?a:b;
}
int fd(int m)
{
	if(a[m]==m) return m;
	else fd(a[m]);
}
void wiyd(int w,int e)
{
	int x,y;
	x=fd(w);
	y=fd(e);
	if(x!=y) a[x]=y;
}
int main()
{
	int n,m,k,i,j;
	scanf("%d%d%d",&n,&m,&k);
	for(i=1;i<=n;i++)
	{
		scanf("%d",&b[i]);
		a[i]=i;
	}
	for(i=1;i<=m;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		wiyd(x,y);
	}
	int sum=0,bj=0;
	for(i=1;i<=n;i++)
	{
		if(a[i]==i) s[i]=++bj;
	}
	for(i=1;i<=n;i++)
	{
		v[s[fd(i)]].push_back(b[i]);
	}
	for(i=1;i<=bj;i++)
	{
		int mx=0;
		k=v[i].size();
		mp.clear();
		for(j=0;j<=k-1;j++)
		{
			mp[v[i][j]]++;
			mx=max(mx,mp[v[i][j]]);
		}
		sum+=k-mx;
	}
	cout<<sum<<endl;
}


#include<vector>
#include<iostream>
#include<stdio.h>
#include<map>
using namespace std;
int a[200001],b[200001],s[200001];
vector<int> v[200000];
map<int,int> mp;
int max(int a,int b)
{
	return a>b?a:b;
}
int fd(int m)
{
	if(a[m]==m) return m;
	else fd(a[m]);
}
void wiyd(int x,int y)
{
	a[fd(x)]=fd(y);
}
int main()
{
	int n,m,k,i,j;
	scanf("%d%d%d",&n,&m,&k);
	for(i=1;i<=n;i++)
	{
		scanf("%d",&b[i]);
		a[i]=i;
	}
	for(i=1;i<=m;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		wiyd(x,y);
	}
	int sum=0,bj=0;
	for(i=1;i<=n;i++)
	{
		if(a[i]==i) s[i]=++bj;
	}
	for(i=1;i<=n;i++)
	{
		v[s[fd(i)]].push_back(b[i]);
	}
	for(i=1;i<=bj;i++)
	{
		int mx=0;
		k=v[i].size();
		mp.clear();
		for(j=0;j<=k-1;j++)
		{
			mp[v[i][j]]++;
			mx=max(mx,mp[v[i][j]]);
		}
		sum+=k-mx;
	}
	cout<<sum<<endl;
}


#include <iostream>
#include <vector>
#include <queue>

using namespace std;

vector <int> v[200100];
queue <int> q;
int fr[200100];
int t[200100];
int nr,c[200100];
int viz[200100];
int n,m,a,b,mx,ans,k,i;

void df(int x)
{
    if(viz[x])
        return ;
    viz[x]=1;
    fr[c[x]]++;
    ++nr;
    if(fr[c[x]]==1)
        q.push(c[x]);
    mx=max(mx,fr[c[x]]);
    for(int i=0; i<v[x].size(); ++i)
        df(v[x][i]);
}

int main()
{
    cin>>n>>m>>k;
    for(i=1; i<=n; ++i)
        cin>>c[i];
    int a,b;
    for(i=1; i<=m; ++i)
    {
        cin>>a>>b;
        v[a].push_back(b);
        t[b]=a;
    }
    for(i=1; i<=n; ++i)
        if(!viz[i] && t[i]==0)
        {
            mx=0;
            nr=0;
            df(i);
            ans+=nr-mx;
            while(q.size())
            {
                int x = q.front();
                fr[x]=0;
                q.pop();
            }
        }
    cout<<ans;
}


#include <iostream>

using namespace std;

int n,c[200100];
int m,k,l[200100],r[200100];
int i,nr;

int main()
{
    cin>>n>>m>>k;
    for(i=1; i<=n; ++i)
        cin>>c[i];
    for(i=1; i<=m; ++i)
    {
        cin>>l[i]>>r[i];
        if(c[l[i]]!=c[r[i]])
            ++nr;
    }
    cout<<nr;
}


#include <iostream>
#include <vector>
#include <queue>
using namespace std;

int n,c[200100];
int m,k;
int i,nr;
int viz[200100];
int t[200100];
int f[200100];
int fr[200100],mx,ans;
queue <int> q;

void df(int x)
{
    if(viz[x])
       return;
       ++nr;
    viz[x]=1;
    fr[c[x]]++;
    if(fr[c[x]]==1)
        q.push(c[x]);
    mx=max(mx,fr[c[x]]);
    if(f[x]!=0)
        df(f[x]);
}

int main()
{
    cin>>n>>m>>k;
    for(i=1; i<=n; ++i)
        cin>>c[i];
    int a,b;
    for(i=1; i<=m; ++i)
    {
        cin>>a>>b;
        t[b]=a;
        f[a]=b;
    }
    for(i=1; i<=n; ++i)
        if(!viz[i] && t[i]==0)
        {
            mx=0;
            nr=0;
            df(i);
            ans+=nr-mx;
            while(q.size())
            {
                int x = q.front();
                fr[x]=0;
                q.pop();
            }
        }
    cout<<ans;
}


#include <iostream>
#include <vector>
#include <queue>

using namespace std;

vector <int> v[200100];
queue <int> q;
int fr[200100];
int nr,c[200100];
int viz[200100];
int n,m,a,b,mx,ans,k,i;

void df(int x)
{
    if(viz[x])
        return ;
    viz[x]=1;
    fr[c[x]]++;
    ++nr;
    if(fr[c[x]]==1)
        q.push(c[x]);
    mx=max(mx,fr[c[x]]);
    for(int i=0; i<v[x].size(); ++i)
        df(v[x][i]);
}

int main()
{
    cin>>n>>m>>k;
    for(i=1; i<=n; ++i)
        cin>>c[i];
    int a,b;
    for(i=1; i<=m; ++i)
    {
        cin>>a>>b;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    for(i=1; i<=n; ++i)
        if(!viz[i])
        {
            mx=0;
            nr=0;
            df(i);
            ans+=nr-mx;
            while(q.size())
            {
                int x = q.front();
                fr[x]=0;
                q.pop();
            }
        }
    cout<<ans;
}


#include<vector>
#include<iostream>
#include<stdio.h>
#include<map>
using namespace std;

static int maxValue, all;
static int c[200000];
vector<int> mat[200000];
static bool used[200000];
static map<int,int> colors;

void dfs(int i) {
	if (used[i]) return;
	used[i] = true;
	int col = c[i];
	int val;
	if (colors.find(col) == colors.end()) {
		colors[col] = 1;
		val = 1;
	} else {
		val = ++colors[col];
	}
	all++;
	maxValue = max(val, maxValue);
	for (int j = 0; j < mat[i].size(); j++) {
		dfs(mat[i][j]);
	}
}

int main() {
	int n, m, k;
	scanf("%d %d %d", &n, &m, &k);

	for (int i = 0; i < n; i++) {
		scanf("%d", &c[i]);
		c[i]--;
	}
	int l,r;
	for (int i = 0; i < m; i++) {
		scanf("%d %d", &l, &r);
		l--;
		r--;
		mat[l].push_back(r);
		mat[r].push_back(l);
	}
	int res = 0;
	if (m == 0) {
		cout << m;
		return 0;
	}
	for(int i = 0; i < n; i++) {
		if (used[i]) continue;
		maxValue = 0;
		all = 0;
		colors.clear();
		dfs(i);
		res += all - maxValue;
	}
	cout << res;
}


#include<vector>
#include<iostream>
#include<stdio.h>
using namespace std;

static int maxValue, all;
static int c[200000];
vector<int> mat[200000];
static bool used[200000];
static int colors[200000];

void dfs(int i) {
	if (used[i]) return;
	used[i] = true;
	int col = c[i];
	colors[col]++;
	all++;
	maxValue = max(colors[col], maxValue);
	for (int j = 0; j < mat[i].size(); j++) {
		dfs(mat[i][j]);
	}
}

int main() {
	int n, m, k;
	scanf("%d %d %d", &n, &m, &k);

	for (int i = 0; i < n; i++) {
		scanf("%d", &c[i]);
		c[i]--;
	}
	int l,r;
	for (int i = 0; i < m; i++) {
		scanf("%d %d", &l, &r);
		l--;
		r--;
		mat[l].push_back(r);
		mat[r].push_back(l);
	}
	int res = 0;
	for(int i = 0; i < n; i++) {
		if (used[i]) continue;
		maxValue = 0;
		all = 0;
		for (int j = 0; j < k; j++) {
			colors[j] = 0;
		}
		dfs(i)
		res += all - maxValue;
	}
	cout << res;
}


#include<vector>
#include<iostream>
#include<stdio.h>
using namespace std;

static int maxValue, all;
static int c[200000];
vector<int> mat[200000];
static bool used[200000];
static int colors[200000];

void dfs(int i) {
	if (used[i]) return;
	used[i] = true;
	int col = c[i];
	colors[col]++;
	all++;
	maxValue = max(colors[col], maxValue);
	for (int j = 0; j < mat[i].size(); j++) {
		dfs(mat[i][j]);
	}
}

int main() {
	int n, m, k;
	scanf("%d %d %d", &n, &m, &k);

	for (int i = 0; i < n; i++) {
		scanf("%d", &c[i]);
		c[i]--;
	}
	int l,r;
	for (int i = 0; i < m; i++) {
		scanf("%d %d", &l, &r);
		l--;
		r--;
		mat[l].push_back(r);
		mat[r].push_back(l);
	}
	int res = 0;
	for(int i = 0; i < n; i++) {
		if (used[i]) continue;
		maxValue = 0;
		all = 0;
		for (int j = 0; j < k; j++) {
			colors[j] = 0;
		}
		dfs(i);
		res += all - maxValue;
	}
	cout << res;
}


#include<vector>
#include<iostream>
#include<stdio.h>
#include<map>
using namespace std;

static int maxValue, all;
static int c[200000];
vector<int> mat[200000];
static bool used[200000];
static map<int> colors;

void dfs(int i) {
	if (used[i]) return;
	used[i] = true;
	int col = c[i];
	int val;
	if (colors.find(col) == colors.end()) {
		colors[col] = 1;
		val = 1;
	} else {
		val = ++colors[col];
	}
	all++;
	maxValue = max(val, maxValue);
	for (int j = 0; j < mat[i].size(); j++) {
		dfs(mat[i][j]);
	}
}

int main() {
	int n, m, k;
	scanf("%d %d %d", &n, &m, &k);

	for (int i = 0; i < n; i++) {
		scanf("%d", &c[i]);
		c[i]--;
	}
	int l,r;
	for (int i = 0; i < m; i++) {
		scanf("%d %d", &l, &r);
		l--;
		r--;
		mat[l].push_back(r);
		mat[r].push_back(l);
	}
	int res = 0;
	if (m == 0) {
		cout << m;
		return 0;
	}
	for(int i = 0; i < n; i++) {
		if (used[i]) continue;
		maxValue = 0;
		all = 0;
		colors.clear();
		dfs(i);
		res += all - maxValue;
	}
	cout << res;
}


#include<vector>
#include<iostream>
#include<stdio.h>
using namespace std;

static int maxValue, all;
static int c[200000];
vector<int> mat[200000];
static bool used[200000];
static int colors[200000];

void dfs(int i) {
	if (used[i]) return;
	used[i] = true;
	int col = c[i];
	colors[col]++;
	all++;
	maxValue = max(colors[col], maxValue);
	for (int j = 0; j < mat[i].size()) {
		dfs(mat[i][j]);
	}
}

int main() {
	int n, m, k;
	scanf("%d %d %d", &n, &m, &k);

	for (int i = 0; i < n; i++) {
		scanf("%d", &c[i]);
		c[i]--;
	}
	int l,r;
	for (int i = 0; i < m; i++) {
		scanf("%d %d", &l, &r);
		l--;
		r--;
		mat[l].push_back(r);
		mat[r].push_back(l);
	}
	int res = 0;
	for(int i = 0; i < n; i++) {
		if (used[i]) continue;
		maxValue = 0;
		all = 0;
		for (int j = 0; j < k; j++) {
			colors[j] = 0;
		}
		dfs(i)
		res += all - maxValue;
	}
	cout << res;
}


#include<vector>
#include<iostream>
#include<stdio.h>
using namespace std;

static int maxValue, all;
static int c[200000];
vector<int> mat[200000];
static bool used[200000];
static int colors[200000];

void dfs(int i) {
	if (used[i]) return;
	used[i] = true;
	int col = c[i];
	colors[col]++;
	all++;
	maxValue = max(colors[col], maxValue);
	for (int j = 0; j < mat[i].size(); j++) {
		dfs(mat[i][j]);
	}
}

int main() {
	int n, m, k;
	scanf("%d %d %d", &n, &m, &k);

	for (int i = 0; i < n; i++) {
		scanf("%d", &c[i]);
		c[i]--;
	}
	int l,r;
	for (int i = 0; i < m; i++) {
		scanf("%d %d", &l, &r);
		l--;
		r--;
		mat[l].push_back(r);
		mat[r].push_back(l);
	}
	int res = 0;
	if (m == 0) {
		cout << m;
		return 0;
	}
	for(int i = 0; i < n; i++) {
		if (used[i]) continue;
		maxValue = 0;
		all = 0;
		for (int j = 0; j < k; j++) {
			colors[j] = 0;
		}
		dfs(i);
		res += all - maxValue;
	}
	cout << res;
}


#include <bits/stdc++.h>

using namespace std;

const long long Size = 500000 + 5;

long long n, m, k, res, a[Size], parent[Size], Rank[Size];

long long Find_Set(long long i)
{
    if (a[i] == parent[i])
        return parent[i];
    else return Find_Set(parent[i]);
}

void Union(long long x, long long y)
{
    if (Rank[x] > Rank[y])
        parent[y] = x;
    else if (Rank[y] > Rank[x])
        parent[x] = y;
    else
    {
        parent[y] = x;
        Rank[x]++;
    }

    res++;
}

void Input()
{
    cin >> n >> m >> k;
    for (long long i = 1; i <= n; i++)
    {
        long long colour;
        cin >> colour;
        parent[i] = colour;
        a[i] = colour;
        Rank[i] = 0;
    }

    for (long long i = 1; i <= m; i++)
    {
        long long u, v;
        cin >> u >> v;
        long long x = Find_Set(u);
        long long y = Find_Set(v);
        if (x == y)
            continue;
        else
            Union(x, y);
    }
}

int main()
{
    Input();
    cout << res << '\n';
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int Size = 2 * 100000 + 5;

int n, m, k, res, parent[Size], Rank[Size];

int Find_Set(int i)
{
    if (i == parent[i])
        return i;
    else return parent[i] = Find_Set(parent[i]);
}

void Union(int x, int y)
{
    if (Rank[x] > Rank[y])
        parent[y] = x;
    else if (Rank[y] > Rank[x])
        parent[x] = y;
    else
    {
        parent[y] = x;
        Rank[x]++;
    }

    res++;
}

void Input()
{
    cin >> n >> m >> k;
    for (int i = 1; i <= n; i++)
    {
        int colour;
        cin >> colour;
        parent[i] = colour;
        Rank[i] = 0;
    }

    for (int i = 1; i <= m; i++)
    {
        int u, v;
        cin >> u >> v;
        int x = Find_Set(u);
        int y = Find_Set(v);
        if (x == y)
            continue;
        else
            Union(x, y);
    }
}

int main()
{
    Input();
    cout << res << '\n';
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const long long Size = 500000 + 5;

long long n, m, k, res, a[Size], parent[Size], Rank[Size];

long long Find_Set(long long i)
{
    if (a[i] == parent[i])
        return parent[i];
    else return Find_Set(parent[i]);
}

void Union(long long x, long long y)
{
    if (Rank[x] > Rank[y])
    {
        parent[y] = x;
        a[y] = x;
    }
    else if (Rank[y] > Rank[x])
    {
        parent[x] = y;
        a[x] = y;
    }
    else
    {
        parent[y] = x;
        a[y] = x;
        Rank[x]++;
    }

    res++;
}

void Input()
{
    cin >> n >> m >> k;
    for (long long i = 1; i <= n; i++)
    {
        long long colour;
        cin >> colour;
        parent[i] = colour;
        a[i] = colour;
        Rank[i] = 0;
    }

    for (long long i = 1; i <= m; i++)
    {
        long long u, v;
        cin >> u >> v;
        long long x = Find_Set(u);
        long long y = Find_Set(v);
        if (x == y)
            continue;
        else
            Union(x, y);
    }
}

int main()
{
    Input();
    cout << res << '\n';
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const long long Size = 500000 + 5;

long long n, m, k, res, a[Size], parent[Size];

long long Find_Set(long long i)
{
    if (a[i] == parent[i])
        return parent[i];
    else return parent[i] = Find_Set(parent[i]);
}

void Union(long long x, long long y)
{
    if (parent[x] > parent[y])
    {
        parent[y] = x;
        a[y] = x;
    }
    else if (parent[y] > parent[x])
    {
        parent[x] = y;
        a[x] = y;
    }
    else
    {
        parent[y] = x;
        a[y] = x;
    }

    res++;
}

void Input()
{
    cin >> n >> m >> k;
    for (long long i = 1; i <= n; i++)
    {
        long long colour; cin >> colour;
        parent[i] = colour;
        a[i] = colour;
        Rank[i] = 0;
    }

    for (long long i = 1; i <= m; i++)
    {
        long long u, v;
        cin >> u >> v;
        long long x = Find_Set(u);
        long long y = Find_Set(v);
        if (x == y)
            continue;

        else
            Union(x, y);
    }
}

int main()
{
    Input();
    cout << res << '\n';
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const long long Size = 2000000 + 5;

long long n, m, k, res, a[Size], parent[Size], Rank[Size];

long long Find_Set(long long i)
{
    if (a[i] == parent[i])
        return parent[i];
    else return parent[i] = Find_Set(parent[i]);
}

void Union(long long x, long long y)
{
    if (Rank[x] > Rank[y])
        parent[y] = x;
    else if (Rank[y] > Rank[x])
        parent[x] = y;
    else
    {
        parent[y] = x;
        Rank[x]++;
    }

    res++;
}

void Input()
{
    cin >> n >> m >> k;
    for (long long i = 1; i <= n; i++)
    {
        long long colour;
        cin >> colour;
        parent[i] = colour;
        a[i] = colour;
        Rank[i] = 0;
    }

    for (long long i = 1; i <= m; i++)
    {
        long long u, v;
        cin >> u >> v;
        long long x = Find_Set(u);
        long long y = Find_Set(v);
        if (x == y)
            continue;
        else
            Union(x, y);
    }
}

int main()
{
    Input();
    cout << res << '\n';
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const long long Size = 200000 + 5;

long long n, m, k, res, parent[Size], Rank[Size];

long long Find_Set(long long i)
{
    if (i == parent[i])
        return i;
    else return parent[i] = Find_Set(parent[i]);
}

void Union(long long x, long long y)
{
    if (Rank[x] > Rank[y])
        parent[y] = x;
    else if (Rank[y] > Rank[x])
        parent[x] = y;
    else
    {
        parent[y] = x;
        Rank[x]++;
    }

    res++;
}

void Input()
{
    cin >> n >> m >> k;
    for (long long i = 1; i <= n; i++)
    {
        long long colour;
        cin >> colour;
        parent[i] = colour;
        Rank[i] = 0;
    }

    for (long long i = 1; i <= m; i++)
    {
        long long u, v;
        cin >> u >> v;
        long long x = Find_Set(u);
        long long y = Find_Set(v);
        if (x == y)
            continue;
        else
            Union(x, y);
    }
}

int main()
{
    Input();
    cout << res << '\n';
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const long long Size = 20000 + 5;

long long n, m, k, res, a[Size], parent[Size], Rank[Size];

long long Find_Set(long long i)
{
    if (a[i] == parent[i])
        return a[i];
    else return parent[i] = Find_Set(parent[i]);
}

void Union(long long x, long long y)
{
    if (Rank[x] > Rank[y])
        parent[y] = x;
    else if (Rank[y] > Rank[x])
        parent[x] = y;
    else
    {
        parent[y] = x;
        Rank[x]++;
    }

    res++;
}

void Input()
{
    cin >> n >> m >> k;
    for (long long i = 1; i <= n; i++)
    {
        long long colour;
        cin >> colour;
        parent[i] = colour;
        a[i] = colour;
        Rank[i] = 0;
    }

    for (long long i = 1; i <= m; i++)
    {
        long long u, v;
        cin >> u >> v;
        long long x = Find_Set(u);
        long long y = Find_Set(v);
        if (x == y)
            continue;
        else
            Union(x, y);
    }
}

int main()
{
    Input();
    cout << res << '\n';
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const long long Size = 20000 + 5;

long long n, m, k, res, a[Size], parent[Size], Rank[Size];

void Union(long long x, long long y)
{
    if (Rank[x] > Rank[y])
        a[y] = x;
    else if (Rank[y] > Rank[x])
        a[x] = y;
    else
    {
        a[y] = x;
        Rank[x]++;
    }

    res++;
}

void Input()
{
    cin >> n >> m >> k;
    for (long long i = 1; i <= n; i++)
    {
        long long colour;
        cin >> colour;
        parent[i] = colour;
        a[i] = colour;
        Rank[i] = 0;
    }

    for (long long i = 1; i <= m; i++)
    {
        long long u, v;
        cin >> u >> v;
        long long x = a[u];
        long long y = a[v];
        if (x == y)
            continue;
        else
            Union(x, y);
    }
}

int main()
{
    Input();
    cout << res << '\n';
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const long long Size = 500000 + 5;

long long n, m, k, res, a[Size], parent[Size];

long long Find_Set(long long i)
{
    if (a[i] == parent[i])
        return parent[i];
    else return parent[i] = Find_Set(parent[i]);
}

void Union(long long x, long long y)
{
    if (parent[x] > parent[y])
    {
        parent[y] = x;
        a[y] = x;
    }
    else if (parent[y] > parent[x])
    {
        parent[x] = y;
        a[x] = y;
    }
    else
    {
        parent[y] = x;
        a[y] = x;
    }

    res++;
}

void Input()
{
    cin >> n >> m >> k;
    for (long long i = 1; i <= n; i++)
    {
        long long colour; cin >> colour;
        parent[i] = colour;
        a[i] = colour;
    }

    for (long long i = 1; i <= m; i++)
    {
        long long u, v;
        cin >> u >> v;
        long long x = Find_Set(u);
        long long y = Find_Set(v);
        if (x == y)
            continue;

        else
            Union(x, y);
    }
}

int main()
{
    Input();
    cout << res << '\n';
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const long long Size = 1000000 + 5;

long long n, m, k, res, a[Size], parent[Size], Rank[Size];

long long Find_Set(long long i)
{
    if (a[i] == parent[i])
        return parent[i];
    else return parent[i] = Find_Set(parent[i]);
}

void Union(long long x, long long y)
{
    if (Rank[x] > Rank[y])
        parent[y] = x;
    else if (Rank[y] > Rank[x])
        parent[x] = y;
    else
    {
        parent[y] = x;
        Rank[x]++;
    }

    res++;
}

void Input()
{
    cin >> n >> m >> k;
    for (long long i = 1; i <= n; i++)
    {
        long long colour;
        cin >> colour;
        parent[i] = colour;
        a[i] = colour;
        Rank[i] = 0;
    }

    for (long long i = 1; i <= m; i++)
    {
        long long u, v;
        cin >> u >> v;
        long long x = Find_Set(u);
        long long y = Find_Set(v);
        if (x == y)
            continue;
        else
            Union(x, y);
    }
}

int main()
{
    Input();
    cout << res << '\n';
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int N = 2e5 + 5;

int n, m, k, cnt, res, c[N], Rank[N], d[N];
pair<int, int> parent[N];
queue<int> Q[N];

void Input()
{
    cin >> n >> m >> k;
    for (int i = 1; i <= n; i++)
        cin >> c[i];
}

void Init()
{
    for (int i = 1; i <= n; i++)
    {
        parent[i].first = i;
        parent[i].second = c[i];
    }
}

int Find_set(int u)
{
    if (u == parent[u].first)
        return parent[u].first;
    return parent[u].first = Find_set(parent[u].first);
}

void Union(int x, int y)
{
    x = Find_set(x);
    y = Find_set(y);

    if (Rank[x] > Rank[y])
        parent[y].first = x;
    else if (Rank[y] < Rank[x])
        parent[x].first = y;
    else
    {
        parent[y].first = x;
        Rank[x]++;
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    Input();
    Init();
    while (m--)
    {
        int u, v; cin >> u >> v;
        Union(u, v);
    }

    for (int i = 1; i <= n; i++)
        Find_set(i);
    sort(parent + 1, parent + n + 1);
    for (int i = 1; i <= n; i++)
    {
        if (parent[i].first != parent[i - 1].first)
            cnt++, Q[cnt].push(parent[i].second);
        else
            Q[cnt].push(parent[i].second);
    }

    for (int i = 1; i <= cnt; i++)
    {
        int curr = 0;
        while (!Q[i].empty())
        {
            curr++, d[curr] = Q[i].front();
            Q[i].pop();
        }
        sort(d + 1, d + curr + 1);
        int tmp = 0, c_res = 1;
        for (int i = 1; i <= curr; i++)
        {
            if (d[i] == d[i - 1])
                tmp++, c_res = max(c_res, tmp);
            else
                c_res = max(c_res, tmp), tmp = 1;
        }
        res += curr - c_res;
    }
    cout << res << '\n';
    return 0;
}


#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iostream>

#define ll long long int
#define ull unsigned ll
#define SWAP(A,B) (A)=((A)+(B))-((B)=(A))

#define PI 3.14159265
//#define DEBUG(X) cout << (X) << endl;
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define DEBUGL(x) std::cerr << "In " << __FILE__ << " at line " << __LINE__ << #x << ' = ' << x << std::endl;

// inputs
#define inpd(x) scanf("%d",&x)
#define inpc(x) scanf("%c",&x)

using namespace std;

int max(int a, int b)
{
	if(a>=b)
		return a;
	return b;
}

int max3(int a, int b, int c)
{
	return max(a,max(b,c));
}

int gcd(int a, int b)
{
	if(b==0)
		return a;
	return gcd(b,a%b);
}

int c[200001];
int hash[200001];
bool traversed[200001];
int mx=-1,num=0;

vector<int> g[200001];

int dfs(int n, int parent)
{
	//cout<<"At node: "<<n<<" Color: "<<c[n]<<endl;
	hash[c[n]]++;
	if(hash[ c[n] ]>mx) {
		mx=hash[ c[n] ];
	}
	int i;
	for(i=0;i<g[n].size();i++) {
		if(g[n][i]==parent) {
			continue;
		}
		if(!traversed[ g[n][i] ]) {
			num++;
			traversed[ g[n][i] ]=true;
			dfs( g[n][i], n );
		}
	}
	return 0;
}

int main()
{
	int n,m,k;
	//cin>>n>>m>>k;
	scanf("%d %d %d",&n,&m,&k);
	//int c[n];
	int i;
	for(i=1;i<=n;i++) {
		scanf("%d",c+i);
		//cin>>c[i];
	}
	//vector<int> g[n+1];
	//bool traversed[n+1];
	memset(traversed, false, sizeof(traversed));
	int l,r;
	for(i=0;i<m;i++) {
		scanf("%d %d",&l,&r);
		//cin>>l>>r;
		g[l].push_back(r);
		g[r].push_back(l);
	}
	ll ans=0;
	for(i=1;i<=n;i++) {
		if(!traversed[i] && g[i].size()>0) {
			memset(hash, 0, sizeof(hash));
			mx=-1;
			num=1;
			traversed[i]=true;
			dfs(i,-1);
			//cout<<num<<' '<<mx<<endl;
			ans+=(num-mx);
		}
	}
	printf("%lld\n",ans);
	//cout<<ans<<endl;
	return 0;
}


#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iostream>

#define ll long long int
#define ull unsigned ll
#define SWAP(A,B) (A)=((A)+(B))-((B)=(A))

#define PI 3.14159265
//#define DEBUG(X) cout << (X) << endl;
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define DEBUGL(x) std::cerr << "In " << __FILE__ << " at line " << __LINE__ << #x << ' = ' << x << std::endl;

// inputs
#define inpd(x) scanf("%d",&x)
#define inpc(x) scanf("%c",&x)

using namespace std;

int max(int a, int b)
{
	if(a>=b)
		return a;
	return b;
}

int max3(int a, int b, int c)
{
	return max(a,max(b,c));
}

int gcd(int a, int b)
{
	if(b==0)
		return a;
	return gcd(b,a%b);
}

typedef struct node {
	int l;
	int r;
}node;

int n,m,k;
//int c[200001];

int calc(int c[], int index, node qr[])
{
	if(index==m)
		return 0;
	int l,r,i;
	l=qr[index].l;
	r=qr[index].r;
	if(c[l-1]==c[r-1]) {
		return calc(c, index+1, qr);
	} else {
		/*
		int t[n];
		for(i=0;i<n;i++) {
			t[i]=c[i];
		}
		t[l-1]=t[r-1];
		int x=1+calc(t,index+1, qr);
		t[l-1]=c[l-1];
		t[r-1]=c[l-1];
		int y=1+calc(t,index+1, qr);
		return min(x,y);
		*/
		int x_l,x_r;
		x_l=c[l-1];
		x_r=c[r-1];
		c[l-1]=c[r-1];
		int x=1+calc(c,index+1,qr);
		c[l-1]=x_l;
		c[r-1]=c[l-1];
		int y=1+calc(c,index+1,qr);
		return min(x,y);
	}
}

int main()
{
	//int n,m,k;
	cin>>n>>m>>k;
	int c[n];
	int hash[n+1];
	memset(hash, 0, sizeof(hash));
	int i;
	for(i=0;i<n;i++) {
		cin>>c[i];
	}
	node qr[m];
	int l,r;
	for(i=0;i<m;i++) {
		cin>>l>>r;
		qr[i].l=l;
		qr[i].r=r;
	}
	cout<<calc(c,0,qr)<<endl;
	return 0;
}


#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iostream>

#define ll long long int
#define ull unsigned ll
#define SWAP(A,B) (A)=((A)+(B))-((B)=(A))

#define PI 3.14159265
//#define DEBUG(X) cout << (X) << endl;
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define DEBUGL(x) std::cerr << "In " << __FILE__ << " at line " << __LINE__ << #x << ' = ' << x << std::endl;

// inputs
#define inpd(x) scanf("%d",&x)
#define inpc(x) scanf("%c",&x)

using namespace std;

int max(int a, int b)
{
	if(a>=b)
		return a;
	return b;
}

int max3(int a, int b, int c)
{
	return max(a,max(b,c));
}

int gcd(int a, int b)
{
	if(b==0)
		return a;
	return gcd(b,a%b);
}

int c[200001];
int hash[200001];
bool traversed[200001];
int mx=-1,num=0;

int dfs(int n, vector<int> *g, int parent)
{
	//cout<<"At node: "<<n<<" Color: "<<c[n]<<endl;
	hash[c[n]]++;
	if(hash[ c[n] ]>mx) {
		mx=hash[ c[n] ];
	}
	int i;
	for(i=0;i<g[n].size();i++) {
		if(g[n][i]==parent) {
			continue;
		}
		if(!traversed[ g[n][i] ]) {
			num++;
			traversed[ g[n][i] ]=true;
			dfs( g[n][i], g, n );
		}
	}
	return 0;
}

int main()
{
	int n,m,k;
	//cin>>n>>m>>k;
	scanf("%d %d %d",&n,&m,&k);
	//int c[n];
	int i;
	for(i=1;i<=n;i++) {
		scanf("%d",c+i);
		//cin>>c[i];
	}
	vector<int> g[n+1];
	//bool traversed[n+1];
	memset(traversed, false, sizeof(traversed));
	int l,r;
	for(i=0;i<m;i++) {
		scanf("%d %d",&l,&r);
		//cin>>l>>r;
		g[l].push_back(r);
		g[r].push_back(l);
	}
	int ans=0;
	for(i=1;i<=n;i++) {
		if(!traversed[i] && g[i].size()>0) {
			memset(hash, 0, sizeof(hash));
			mx=-1;
			num=1;
			traversed[i]=true;
			dfs(i,g, -1);
			//cout<<num<<' '<<mx<<endl;
			ans+=(num-mx);
		}
	}
	printf("%d\n",ans);
	//cout<<ans<<endl;
	return 0;
}


#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iostream>

#define ll long long int
#define ull unsigned ll
#define SWAP(A,B) (A)=((A)+(B))-((B)=(A))

#define PI 3.14159265
//#define DEBUG(X) cout << (X) << endl;
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define DEBUGL(x) std::cerr << "In " << __FILE__ << " at line " << __LINE__ << #x << ' = ' << x << std::endl;

// inputs
#define inpd(x) scanf("%d",&x)
#define inpc(x) scanf("%c",&x)

using namespace std;

int max(int a, int b)
{
	if(a>=b)
		return a;
	return b;
}

int max3(int a, int b, int c)
{
	return max(a,max(b,c));
}

int gcd(int a, int b)
{
	if(b==0)
		return a;
	return gcd(b,a%b);
}

int c[200001];
int hash[200001];
bool traversed[200001];
int mx=-1,num=0;

int dfs(int n, vector<int> *g)
{
	//cout<<"At node: "<<n<<" Color: "<<c[n]<<endl;
	hash[c[n]]++;
	if(hash[ c[n] ]>mx) {
		mx=hash[ c[n] ];
	}
	int i;
	for(i=0;i<g[n].size();i++) {
		if(!traversed[ g[n][i] ]) {
			num++;
			traversed[ g[n][i] ]=true;
			dfs( g[n][i], g );
		}
	}
	return 0;
}

int main()
{
	int n,m,k;
	cin>>n>>m>>k;
	//int c[n];
	int i;
	for(i=1;i<=n;i++) {
		cin>>c[i];
	}
	vector<int> g[n+1];
	//bool traversed[n+1];
	memset(traversed, false, sizeof(traversed));
	int l,r;
	for(i=0;i<m;i++) {
		cin>>l>>r;
		g[l].push_back(r);
		g[r].push_back(l);
	}
	int ans=0;
	for(i=1;i<=n;i++) {
		if(!traversed[i] && g[i].size()>0) {
			memset(hash, 0, sizeof(hash));
			mx=-1;
			num=1;
			traversed[i]=true;
			dfs(i,g);
			cout<<num<<' '<<mx<<endl;
			ans+=(num-mx);
		}
	}
	cout<<ans<<endl;
	return 0;
}


#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iostream>

#define ll long long int
#define ull unsigned ll
#define SWAP(A,B) (A)=((A)+(B))-((B)=(A))

#define PI 3.14159265
//#define DEBUG(X) cout << (X) << endl;
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define DEBUGL(x) std::cerr << "In " << __FILE__ << " at line " << __LINE__ << #x << ' = ' << x << std::endl;

// inputs
#define inpd(x) scanf("%d",&x)
#define inpc(x) scanf("%c",&x)

using namespace std;

int max(int a, int b)
{
	if(a>=b)
		return a;
	return b;
}

int max3(int a, int b, int c)
{
	return max(a,max(b,c));
}

int gcd(int a, int b)
{
	if(b==0)
		return a;
	return gcd(b,a%b);
}

int c[200001];
int hash[200001];
bool traversed[200001];
int mx=-1,num=0;

int dfs(int n, vector<int> *g, int parent)
{
	//cout<<"At node: "<<n<<" Color: "<<c[n]<<endl;
	hash[c[n]]++;
	if(hash[ c[n] ]>mx) {
		mx=hash[ c[n] ];
	}
	int i;
	for(i=0;i<g[n].size();i++) {
		if(g[n][i]==parent) {
			continue;
		}
		if(!traversed[ g[n][i] ]) {
			num++;
			traversed[ g[n][i] ]=true;
			dfs( g[n][i], g, n );
		}
	}
	return 0;
}

int main()
{
	int n,m,k;
	cin>>n>>m>>k;
	//int c[n];
	int i;
	for(i=1;i<=n;i++) {
		cin>>c[i];
	}
	vector<int> g[n+1];
	//bool traversed[n+1];
	memset(traversed, false, sizeof(traversed));
	int l,r;
	for(i=0;i<m;i++) {
		cin>>l>>r;
		g[l].push_back(r);
		g[r].push_back(l);
	}
	int ans=0;
	for(i=1;i<=n;i++) {
		if(!traversed[i] && g[i].size()>0) {
			memset(hash, 0, sizeof(hash));
			mx=-1;
			num=1;
			traversed[i]=true;
			dfs(i,g, -1);
			//cout<<num<<' '<<mx<<endl;
			ans+=(num-mx);
		}
	}
	cout<<ans<<endl;
	return 0;
}


#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iostream>

#define ll long long int
#define ull unsigned ll
#define SWAP(A,B) (A)=((A)+(B))-((B)=(A))

#define PI 3.14159265
//#define DEBUG(X) cout << (X) << endl;
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define DEBUGL(x) std::cerr << "In " << __FILE__ << " at line " << __LINE__ << #x << ' = ' << x << std::endl;

// inputs
#define inpd(x) scanf("%d",&x)
#define inpc(x) scanf("%c",&x)

using namespace std;

int max(int a, int b)
{
	if(a>=b)
		return a;
	return b;
}

int max3(int a, int b, int c)
{
	return max(a,max(b,c));
}

int gcd(int a, int b)
{
	if(b==0)
		return a;
	return gcd(b,a%b);
}

int c[200001];
int hash[200001];
bool traversed[200001];
int mx=-1,num=0;

vector<int> g[200001];

map<int,int> sd;

int dfs(int n, int parent)
{
	//cout<<"At node: "<<n<<" Color: "<<c[n]<<endl;
	//hash[c[n]]++;
	sd[ c[n] ]++;
	if(sd[ c[n] ]>mx) {
		mx=sd[ c[n] ];
	}
	/*
	if(hash[ c[n] ]>mx) {
		mx=hash[ c[n] ];
	}
	*/
	int i;
	for(i=0;i<g[n].size();i++) {
		if(g[n][i]==parent) {
			continue;
		}
		if(!traversed[ g[n][i] ]) {
			num++;
			traversed[ g[n][i] ]=true;
			dfs( g[n][i], n );
		}
	}
	return 0;
}

int main()
{
	int n,m,k;
	//cin>>n>>m>>k;
	scanf("%d %d %d",&n,&m,&k);
	//int c[n];
	int i;
	for(i=1;i<=n;i++) {
		scanf("%d",c+i);
		//cin>>c[i];
	}
	//vector<int> g[n+1];
	//bool traversed[n+1];
	memset(traversed, false, sizeof(traversed));
	int l,r;
	for(i=0;i<m;i++) {
		scanf("%d %d",&l,&r);
		//cin>>l>>r;
		g[l].push_back(r);
		g[r].push_back(l);
	}
	ll ans=0;
	for(i=1;i<=n;i++) {
		if(!traversed[i] && g[i].size()>0) {
			//memset(hash, 0, sizeof(hash));
			mx=-1;
			num=1;
			traversed[i]=true;
			dfs(i,-1);
			//cout<<num<<' '<<mx<<endl;
			ans+=(num-mx);
			sd.clear();
		}
	}
	printf("%lld\n",ans);
	//cout<<ans<<endl;
	return 0;
}