#include<stdio.h>
#include<stdbool.h>
#include<stdlib.h>

int uf[100000];

int root(int n){
    return uf[n] == n ? n : (uf[n] = root(uf[n]));
}

void marge(int a,int b){
    int pa = root(a);
    int pb = root(b);
    if(pa == pb)return;
    uf[pa] = pb;
}

int fn(const void *a,const void *b){
    return *(int*)a - *(int*)b;
}

int main(void){
    register int i;
    int n,m;
    scanf("%d%d",&n,&m);
    long h[n];
    for(i = 0;i < n;i++)scanf("%ld",&h[i]);
    for(i = 0;i < n;i++)uf[i] = i;
    for(i = 0;i < m;i++){
        int a,b;
        scanf("%d%d",&a,&b);
        marge(a,b);
    }
    qsort(uf,n,sizeof(int),fn);
    int cnt = 1;
    for(i = 1;i < n;i++)if(uf[i-1] != uf[i])cnt++;
    printf("%d",cnt);
}  