import java.io.*;
import java.text.DecimalFormat;
import java.util.*;
import java.io.IOException;
import java.io.InputStream;
import java.util.stream.Collector;
import java.util.stream.Collectors;

public class Main {
    public static void main(String[] args) {

        File file = new File("in.txt");
        InputStream inputStream = null;
        // try {inputStream= new FileInputStream(file);} catch (FileNotFoundException ex){return;};
        inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }
}

class TaskB {

    public void solve(int testNumber, InputReader in, PrintWriter out) {

        Integer socks = in.nextInt();
        Integer days = in.nextInt();
        Integer colors = in.nextInt();
        int[] sockToColor = new int[socks+1];

        for(int i=1; i<=socks; i++){
            sockToColor[i]=in.nextInt();
        }

        Set<Integer> usedNodes = new HashSet<>();
        List<List<Integer>> edges = new ArrayList<>(socks+1);
        for(int i=0; i<=socks; i++){
            edges.add(new ArrayList<>());
        }

        for(int i=0; i<days; i++){
            Integer leftSock = in.nextInt();
            Integer rightSock = in.nextInt();
            usedNodes.add(leftSock);
            usedNodes.add(rightSock);

            edges.get(leftSock).add(rightSock);
            edges.get(rightSock).add(leftSock);
        }

        Integer sum = 0;
        while(!usedNodes.isEmpty()){
            Integer node = usedNodes.iterator().next();

            int [] colorCounts = new int[colors+1];
            Integer componentSize = 0;
            Queue<Integer> q = new ArrayDeque<>();
            q.add(node);

            while(!q.isEmpty()){
                Integer currentNode  = q.poll();
                if(!usedNodes.contains(currentNode)){
                    continue;
                }
                usedNodes.remove(currentNode);

                componentSize+=1;
                Integer nodeColor = sockToColor[currentNode];
                colorCounts[nodeColor]+=1;

                for(Integer target : edges.get(currentNode)){
                    q.add(target);
                }

            }

            sum+=componentSize - Arrays.stream(colorCounts).max().getAsInt();

        }

        out.println(sum);

    }

}

class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream), 32768);
        tokenizer = null;
    }

    public String next() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine(){
        try {
            return reader.readLine();
        } catch (IOException e){
            throw new RuntimeException(e);
        }
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }
    public long nextLong() { return Long.parseLong(next()); }

}

class Pair<F, S> {
    public final F first;
    public final S second;

    public Pair(F first, S second) {
        this.first = first;
        this.second = second;
    }

    @Override
    public boolean equals(Object o) {
        if (!(o instanceof Pair)) {
            return false;
        }
        Pair<?, ?> p = (Pair<?, ?>) o;
        return Objects.equals(p.first, first) && Objects.equals(p.second, second);
    }

    @Override
    public int hashCode() {
        return (first == null ? 0 : first.hashCode()) ^ (second == null ? 0 : second.hashCode());
    }

    @Override
    public String toString() {
        return "(" + first + ", " + second + ')';
    }
}


import java.io.*;
import java.text.DecimalFormat;
import java.util.*;
import java.io.IOException;
import java.io.InputStream;
import java.util.stream.Collector;
import java.util.stream.Collectors;

public class Main {
    public static void main(String[] args) {

        File file = new File("in.txt");
        InputStream inputStream = null;
//        try {inputStream= new FileInputStream(file);} catch (FileNotFoundException ex){return;};
        inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }
}

class TaskB {

    public void solve(int testNumber, InputReader in, PrintWriter out) {

        Integer socks = in.nextInt();
        Integer days = in.nextInt();
        Integer colors = in.nextInt();
        int[] sockToColor = new int[colors+1];

        for(int i=1; i<=socks; i++){
            sockToColor[i]=in.nextInt();
        }

        Set<Integer> usedNodes = new HashSet<>();
        Map<Integer, Set<Integer>> edges = new HashMap<>();
        for(int i=0; i<days; i++){
            Integer leftSock = in.nextInt();
            Integer rightSock = in.nextInt();
            usedNodes.add(leftSock);
            usedNodes.add(rightSock);
            Set<Integer> leftSockEdges = edges.getOrDefault(leftSock, new HashSet<>());
            Set<Integer> rightSockEdges = edges.getOrDefault(rightSock, new HashSet<>());
            leftSockEdges.add(rightSock);
            rightSockEdges.add(leftSock);
            edges.put(leftSock,leftSockEdges);
            edges.put(rightSock,rightSockEdges);
        }

        Integer sum = 0;
        while(!usedNodes.isEmpty()){
            Integer node = usedNodes.iterator().next();

            int [] colorCounts = new int[colors+1];
            Integer componentSize = 0;
            Queue<Integer> q = new ArrayDeque<>();
            q.add(node);

            Set<Integer> visited = new HashSet<>();
            while(!q.isEmpty()){
                Integer currentNode  = q.poll();
                if(!usedNodes.contains(currentNode)){
                    continue;
                }
                usedNodes.remove(currentNode);

                componentSize+=1;
                Integer nodeColor = sockToColor[currentNode];
                colorCounts[nodeColor]+=1;

                for(Integer target : edges.get(currentNode)){
                    q.add(target);
                }

            }

            sum+=componentSize - Arrays.stream(colorCounts).max().getAsInt();

        }

        out.println(sum);

    }

}

class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream), 32768);
        tokenizer = null;
    }

    public String next() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine(){
        try {
            return reader.readLine();
        } catch (IOException e){
            throw new RuntimeException(e);
        }
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }
    public long nextLong() { return Long.parseLong(next()); }

}

class Pair<F, S> {
    public final F first;
    public final S second;

    public Pair(F first, S second) {
        this.first = first;
        this.second = second;
    }

    @Override
    public boolean equals(Object o) {
        if (!(o instanceof Pair)) {
            return false;
        }
        Pair<?, ?> p = (Pair<?, ?>) o;
        return Objects.equals(p.first, first) && Objects.equals(p.second, second);
    }

    @Override
    public int hashCode() {
        return (first == null ? 0 : first.hashCode()) ^ (second == null ? 0 : second.hashCode());
    }

    @Override
    public String toString() {
        return "(" + first + ", " + second + ')';
    }
}


import java.io.*;
import java.text.DecimalFormat;
import java.util.*;
import java.io.IOException;
import java.io.InputStream;
import java.util.stream.Collector;
import java.util.stream.Collectors;

public class Main {
    public static void main(String[] args) {

        File file = new File("in.txt");
        InputStream inputStream = null;
//        try {inputStream= new FileInputStream(file);} catch (FileNotFoundException ex){return;};
        inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }
}

class TaskB {

    public void solve(int testNumber, InputReader in, PrintWriter out) {

        Integer socks = in.nextInt();
        Integer days = in.nextInt();
        Integer colors = in.nextInt();
        Map<Integer,Integer> sockToColor  = new HashMap<>(socks);

        for(int i=1; i<=socks; i++){
            sockToColor.put(i,in.nextInt());
        }

        Set<Integer> usedNodes = new HashSet<>();
        Map<Integer, Set<Integer>> edges = new HashMap<>();
        for(int i=0; i<days; i++){
            Integer leftSock = in.nextInt();
            Integer rightSock = in.nextInt();
            usedNodes.add(leftSock);
            usedNodes.add(rightSock);
            Set<Integer> leftSockEdges = edges.getOrDefault(leftSock, new HashSet<>());
            Set<Integer> rightSockEdges = edges.getOrDefault(rightSock, new HashSet<>());
            leftSockEdges.add(rightSock);
            rightSockEdges.add(leftSock);
            edges.put(leftSock,leftSockEdges);
            edges.put(rightSock,rightSockEdges);
        }

        Integer sum = 0;
        while(!usedNodes.isEmpty()){
            Integer node = usedNodes.iterator().next();
            Map<Integer,Integer> colorCounts = new HashMap<>();
            Integer componentSize = 0;
            Queue<Integer> q = new ArrayDeque<>();
            q.add(node);
            Set<Integer> visited = new HashSet<>();
            while(!q.isEmpty()){
                Integer currentNode  = q.poll();
                if(visited.contains(currentNode)){
                    continue;
                }
                visited.add(currentNode);
                usedNodes.remove(currentNode);

                componentSize+=1;
                Integer nodeColor = sockToColor.get(currentNode);
                Integer nodeColorCount = colorCounts.getOrDefault(nodeColor,0);
                colorCounts.put(nodeColor,nodeColorCount+1);

                for(Integer target : edges.get(currentNode)){
                    q.add(target);
                }

            }

            sum+=componentSize - Collections.max(colorCounts.values());

        }

        out.println(sum);

    }

}

class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream), 32768);
        tokenizer = null;
    }

    public String next() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine(){
        try {
            return reader.readLine();
        } catch (IOException e){
            throw new RuntimeException(e);
        }
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }
    public long nextLong() { return Long.parseLong(next()); }

}

class Pair<F, S> {
    public final F first;
    public final S second;

    public Pair(F first, S second) {
        this.first = first;
        this.second = second;
    }

    @Override
    public boolean equals(Object o) {
        if (!(o instanceof Pair)) {
            return false;
        }
        Pair<?, ?> p = (Pair<?, ?>) o;
        return Objects.equals(p.first, first) && Objects.equals(p.second, second);
    }

    @Override
    public int hashCode() {
        return (first == null ? 0 : first.hashCode()) ^ (second == null ? 0 : second.hashCode());
    }

    @Override
    public String toString() {
        return "(" + first + ", " + second + ')';
    }
}


import java.io.*;
import java.text.DecimalFormat;
import java.util.*;
import java.io.IOException;
import java.io.InputStream;
import java.util.stream.Collector;
import java.util.stream.Collectors;

public class Main {
    public static void main(String[] args) {

        File file = new File("in.txt");
        InputStream inputStream = null;
//        try {inputStream= new FileInputStream(file);} catch (FileNotFoundException ex){return;};
        inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }
}

class TaskB {

    public void solve(int testNumber, InputReader in, PrintWriter out) {

        Integer socks = in.nextInt();
        Integer days = in.nextInt();
        Integer colors = in.nextInt();
        Map<Integer,Integer> sockToColor  = new HashMap<>(socks);

        for(int i=1; i<=socks; i++){
            sockToColor.put(i,in.nextInt());
        }

        DSU dsu = new DSU();

        for(int i=0; i<days; i++){
            Integer leftSock = in.nextInt();
            Integer rightSock = in.nextInt();
            dsu.makeSet(leftSock, sockToColor.get(leftSock));
            dsu.makeSet(rightSock, sockToColor.get(rightSock));
            dsu.mergeSets(leftSock,rightSock);
        }

        Integer sum = 0;
        for(Integer root : dsu.getRoots()){
            Map<Integer,Integer> colorMap = dsu.getColors(root);
            Integer toBeColored = dsu.getSetSize(root) - colorMap.values().stream().max(Integer::max).get();
            sum+=toBeColored;
        }
        out.println(sum);

    }

}

class DSU{
    private Map<Integer, Integer> parent;
    private Map<Integer, Map<Integer, Integer>> colorCount;
    private Map<Integer, Integer> setSize;
    private Set<Integer> roots;
    public DSU(){
        parent = new HashMap<>();
        colorCount = new HashMap<>();
        setSize = new HashMap<>();
        roots = new HashSet<>();
    }

    public void makeSet(Integer node, Integer color){
        if(parent.keySet().contains(node)) {
            return;
        }

        parent.put(node, null);
        roots.add(node);
        Map<Integer,Integer> colors = new HashMap<>();
        colors.put(color,1);
        colorCount.put(node,colors);
        setSize.put(node,1);
    }

    public Integer findParent(Integer node){
        if(!parent.keySet().contains(node)) {
            throw new IllegalArgumentException();
        }
        while(parent.get(node)!= null){
            node = parent.get(node);
        }
        return node;
    }

    public void mergeSets(Integer node1, Integer node2){
        node1 = findParent(node1);
        node2 = findParent(node2);

        parent.put(node2, node1);
        setSize.put(node1, setSize.get(node1) + setSize.get(node2));
        roots.remove(node2);

        Map<Integer, Integer> node1Colors = colorCount.get(node1);
        Map<Integer, Integer> node2Colors = colorCount.get(node2);

        for(Integer color : node2Colors.keySet()){
            node1Colors.put(color, node1Colors.getOrDefault(color,0) + node2Colors.get(color));
        }
        colorCount.remove(node2);
        setSize.remove(node2);
    }

    public Integer getSetSize(Integer node){
        if(!roots.contains(node)){
            node = findParent(node);
        }
        return setSize.get(node);
    }

    public Map<Integer, Integer> getColors(Integer node){
        if(!roots.contains(node)){
            node = findParent(node);
        }
        return colorCount.get(node);
    }

    public Set<Integer> getRoots(){
        return  roots;
    }

}

class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream), 32768);
        tokenizer = null;
    }

    public String next() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine(){
        try {
            return reader.readLine();
        } catch (IOException e){
            throw new RuntimeException(e);
        }
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }
    public long nextLong() { return Long.parseLong(next()); }

}

class Pair<F, S> {
    public final F first;
    public final S second;

    public Pair(F first, S second) {
        this.first = first;
        this.second = second;
    }

    @Override
    public boolean equals(Object o) {
        if (!(o instanceof Pair)) {
            return false;
        }
        Pair<?, ?> p = (Pair<?, ?>) o;
        return Objects.equals(p.first, first) && Objects.equals(p.second, second);
    }

    @Override
    public int hashCode() {
        return (first == null ? 0 : first.hashCode()) ^ (second == null ? 0 : second.hashCode());
    }

    @Override
    public String toString() {
        return "(" + first + ", " + second + ')';
    }
}


import java.io.*;
import java.text.DecimalFormat;
import java.util.*;
import java.io.IOException;
import java.io.InputStream;
import java.util.stream.Collector;
import java.util.stream.Collectors;

public class Main {
    public static void main(String[] args) {

        File file = new File("in.txt");
        InputStream inputStream = null;
//        try {inputStream= new FileInputStream(file);} catch (FileNotFoundException ex){return;};
        inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }
}

class TaskB {

    public void solve(int testNumber, InputReader in, PrintWriter out) {

        Integer socks = in.nextInt();
        Integer days = in.nextInt();
        Integer colors = in.nextInt();
        int[] sockToColor = new int[socks+1];

        for(int i=1; i<=socks; i++){
            sockToColor[i]=in.nextInt();
        }

        Set<Integer> usedNodes = new HashSet<>();
        Map<Integer, Set<Integer>> edges = new HashMap<>();
        for(int i=0; i<days; i++){
            Integer leftSock = in.nextInt();
            Integer rightSock = in.nextInt();
            usedNodes.add(leftSock);
            usedNodes.add(rightSock);
            Set<Integer> leftSockEdges = edges.getOrDefault(leftSock, new HashSet<>());
            Set<Integer> rightSockEdges = edges.getOrDefault(rightSock, new HashSet<>());
            leftSockEdges.add(rightSock);
            rightSockEdges.add(leftSock);
            edges.put(leftSock,leftSockEdges);
            edges.put(rightSock,rightSockEdges);
        }

        Integer sum = 0;
        while(!usedNodes.isEmpty()){
            Integer node = usedNodes.iterator().next();

            int [] colorCounts = new int[colors+1];
            Integer componentSize = 0;
            Queue<Integer> q = new ArrayDeque<>();
            q.add(node);

            Set<Integer> visited = new HashSet<>();
            while(!q.isEmpty()){
                Integer currentNode  = q.poll();
                if(!usedNodes.contains(currentNode)){
                    continue;
                }
                usedNodes.remove(currentNode);

                componentSize+=1;
                Integer nodeColor = sockToColor[currentNode];
                colorCounts[nodeColor]+=1;

                for(Integer target : edges.get(currentNode)){
                    q.add(target);
                }

            }

            sum+=componentSize - Arrays.stream(colorCounts).max().getAsInt();

        }

        out.println(sum);

    }

}

class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream), 32768);
        tokenizer = null;
    }

    public String next() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine(){
        try {
            return reader.readLine();
        } catch (IOException e){
            throw new RuntimeException(e);
        }
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }
    public long nextLong() { return Long.parseLong(next()); }

}

class Pair<F, S> {
    public final F first;
    public final S second;

    public Pair(F first, S second) {
        this.first = first;
        this.second = second;
    }

    @Override
    public boolean equals(Object o) {
        if (!(o instanceof Pair)) {
            return false;
        }
        Pair<?, ?> p = (Pair<?, ?>) o;
        return Objects.equals(p.first, first) && Objects.equals(p.second, second);
    }

    @Override
    public int hashCode() {
        return (first == null ? 0 : first.hashCode()) ^ (second == null ? 0 : second.hashCode());
    }

    @Override
    public String toString() {
        return "(" + first + ", " + second + ')';
    }
}


import java.io.*;
import java.text.DecimalFormat;
import java.util.*;
import java.io.IOException;
import java.io.InputStream;
import java.util.stream.Collector;
import java.util.stream.Collectors;

public class Main {
    public static void main(String[] args) {

        File file = new File("in.txt");
        InputStream inputStream = null;
//        try {inputStream= new FileInputStream(file);} catch (FileNotFoundException ex){return;};
        inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }
}

class TaskB {

    public void solve(int testNumber, InputReader in, PrintWriter out) {

        Integer socks = in.nextInt();
        Integer days = in.nextInt();
        Integer colors = in.nextInt();
        int[] sockToColor = new int[socks+1];

        for(int i=1; i<=socks; i++){
            sockToColor[i]=in.nextInt();
        }

        boolean[] usedNodes = new boolean[socks+1];
        List<List<Integer>> edges = new ArrayList<>(socks+1);
        for(int i=0; i<=socks; i++){
            edges.add(new ArrayList<>());
        }

        for(int i=0; i<days; i++){
            Integer leftSock = in.nextInt();
            Integer rightSock = in.nextInt();
            usedNodes[leftSock] = Boolean.TRUE;
            usedNodes[rightSock] = Boolean.TRUE;

            edges.get(leftSock).add(rightSock);
            edges.get(rightSock).add(leftSock);
        }

        Integer sum = 0;
        for(int node=1; node<=socks; node++){
            if(!usedNodes[node]){
                continue;
            }

            Map<Integer,Integer> colorCounts = new HashMap<>();
            Integer componentSize = 0;
            Queue<Integer> q = new ArrayDeque<>();
            q.add(node);

            while(!q.isEmpty()){
                Integer currentNode  = q.poll();
                if(!usedNodes[currentNode]){
                    continue;
                }
                usedNodes[currentNode] = Boolean.FALSE;

                componentSize+=1;
                Integer nodeColor = sockToColor[currentNode];
                colorCounts.put(nodeColor,colorCounts.getOrDefault(nodeColor,0)+1);

                for(Integer target : edges.get(currentNode)){
                    q.add(target);
                }

            }

            Integer max = -1;
            for(Integer val : colorCounts.values() ){
                max = Math.max(max, val);
            }

            sum+=componentSize - max;

        }

        out.println(sum);

    }

}

class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream), 32768);
        tokenizer = null;
    }

    public String next() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine(){
        try {
            return reader.readLine();
        } catch (IOException e){
            throw new RuntimeException(e);
        }
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }
    public long nextLong() { return Long.parseLong(next()); }

}

class Pair<F, S> {
    public final F first;
    public final S second;

    public Pair(F first, S second) {
        this.first = first;
        this.second = second;
    }

    @Override
    public boolean equals(Object o) {
        if (!(o instanceof Pair)) {
            return false;
        }
        Pair<?, ?> p = (Pair<?, ?>) o;
        return Objects.equals(p.first, first) && Objects.equals(p.second, second);
    }

    @Override
    public int hashCode() {
        return (first == null ? 0 : first.hashCode()) ^ (second == null ? 0 : second.hashCode());
    }

    @Override
    public String toString() {
        return "(" + first + ", " + second + ')';
    }
}


import java.io.*;
import java.util.*;

public class C {

    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;

    public static void main(String[] args) throws IOException {
        try {
            in = new BufferedReader(new FileReader("unequal.in"));
            out = new PrintWriter(new File("unequal.out"));
        } catch (Exception e) {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(new OutputStreamWriter(System.out));
        }
        tok = new StringTokenizer("");
        new C().solve();
        out.flush();
        out.close();
    }

    String nextTok() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine());
        }
        return tok.nextToken();
    }

    String nextLine() throws IOException {
        return in.readLine();
    }

    int nextInt() throws IOException {
        return Integer.parseInt(nextTok());
    }

    long nextLong() throws IOException {
        return Long.parseLong(nextTok());
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(nextTok());
    }

    class Pair implements Comparable<Pair>{
        int a;
        int b;

        Pair(int a, int b) {
            this.a = a;
            this.b = b;
        }

        @Override
        public int compareTo(Pair o) {
            return 0;
        }
    }

    int[] dsu;
    int[] size;

    int find(int a) {
        if (dsu[a] != a) return dsu[a] = find(dsu[a]);
        return dsu[a];
    }

    void union(int a, int b) {
        a = find(a);
        b = find(b);
        if (a != b) {
            if ((int)Math.round(Math.random()) == 1) {
                dsu[a] = b;
                size[b] += size[a];
            } else {
                dsu[b] = a;
                size[a] += size[b];
            }
        }
    }

    void solve() throws IOException {
        int n = nextInt();
        int m = nextInt();
        int k = nextInt();
        dsu = new int[n];
        size = new int[n];
        int color[] = new int[n];
        for (int i = 0; i < n; i++) {
            color[i] = nextInt()-1;
            dsu[i] = i;
            size[i] = 1;
        }
        int ans = 0;
        for (int i = 0; i < m; i++) {
            int a = nextInt()-1;
            int b = nextInt()-1;
            union(a,b);
        }

        HashSet<Integer> p = new HashSet<>();
        ArrayList<Integer>[] l = new ArrayList[n];

        for (int i = 0; i < n; i++) {
            l[i] = new ArrayList<>();
        }

        for (int i = 0; i < n; i++) {
            int a = find(i);
            l[a].add(i);
            p.add(a);
        }

        int max = 0;
        Iterator<Integer> it = p.iterator();
//        int[] clr;
        while (it.hasNext()) {
            int a = it.next();
            max = 0;
            HashMap<Integer,Integer> mp = new HashMap<>();
//            clr = new int[k];
            for (int v: l[a]) {
                mp.put(color[v],mp.getOrDefault(a,0)+1);
                max = Math.max(mp.get(v),max);
            }
            ans += size[a]-max;

        }

        out.println(ans);
    }

}


import java.io.*;
import java.util.StringTokenizer;

public class C {

    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;

    public static void main(String[] args) throws IOException {
        try {
            in = new BufferedReader(new FileReader("unequal.in"));
            out = new PrintWriter(new File("unequal.out"));
        } catch (Exception e) {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(new OutputStreamWriter(System.out));
        }
        tok = new StringTokenizer("");
        new C().solve();
        out.flush();
        out.close();
    }

    String nextTok() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine());
        }
        return tok.nextToken();
    }

    String nextLine() throws IOException {
        return in.readLine();
    }

    int nextInt() throws IOException {
        return Integer.parseInt(nextTok());
    }

    long nextLong() throws IOException {
        return Long.parseLong(nextTok());
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(nextTok());
    }

    int[] dsu;
    int[] size;

    int find(int a) {
        if (dsu[a] != a) return dsu[a] = find(dsu[a]);
        return dsu[a];
    }

    void union(int a, int b) {
        a = find(a);
        b = find(b);
        if (a != b) {
            if ((int)Math.round(Math.random()) == 1) {
                dsu[a] = b;
                size[b] += size[a];
            } else {
                dsu[b] = a;
                size[a] += size[b];
            }
        }
    }

    void solve() throws IOException {
        int n = nextInt();
        int m = nextInt();
        int k = nextInt();
        dsu = new int[n+1];
        size = new int[n+1];
        int color[] = new int[n+1];
        for (int i = 1; i <= n; i++) {
            color[i] = nextInt();
            dsu[i] = i;
            size[i] = 1;
        }
        int ans = 0;
        for (int i = 0; i < m; i++) {
            int a = nextInt();
            int b = nextInt();
            int aa = find(a);
            int bb = find(b);
            if (color[a] == color[b]) {
                union(a,b);
            } else if (aa != bb) {
                ans += Math.min(size[aa],size[bb]);
                union(a,b);
            }
        }
        if (ans >= n) ans = n-1;
        out.println(ans);
    }

}


import java.io.*;
import java.util.*;

public class C {

    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;

    public static void main(String[] args) throws IOException {
        try {
            in = new BufferedReader(new FileReader("unequal.in"));
            out = new PrintWriter(new File("unequal.out"));
        } catch (Exception e) {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(new OutputStreamWriter(System.out));
        }
        tok = new StringTokenizer("");
        new C().solve();
        out.flush();
        out.close();
    }

    String nextTok() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine());
        }
        return tok.nextToken();
    }

    String nextLine() throws IOException {
        return in.readLine();
    }

    int nextInt() throws IOException {
        return Integer.parseInt(nextTok());
    }

    long nextLong() throws IOException {
        return Long.parseLong(nextTok());
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(nextTok());
    }

    class Pair implements Comparable<Pair>{
        int a;
        int b;

        Pair(int a, int b) {
            this.a = a;
            this.b = b;
        }

        @Override
        public int compareTo(Pair o) {
            return 0;
        }
    }

    int[] dsu;
    int[] size;

    int find(int a) {
        if (dsu[a] != a) return dsu[a] = find(dsu[a]);
        return dsu[a];
    }

    void union(int a, int b) {
        a = find(a);
        b = find(b);
        if (a != b) {
            if ((int)Math.round(Math.random()) == 1) {
                dsu[a] = b;
                size[b] += size[a];
            } else {
                dsu[b] = a;
                size[a] += size[b];
            }
        }
    }

    void solve() throws IOException {
        int n = nextInt();
        int m = nextInt();
        int k = nextInt();
        dsu = new int[n];
        size = new int[n];
        int color[] = new int[n];
        for (int i = 0; i < n; i++) {
            color[i] = nextInt()-1;
            dsu[i] = i;
            size[i] = 1;
        }
        int ans = 0;
        for (int i = 0; i < m; i++) {
            int a = nextInt()-1;
            int b = nextInt()-1;
            union(a,b);
        }

        HashSet<Integer> p = new HashSet<>();
        ArrayList<Integer>[] l = new ArrayList[n];

        for (int i = 0; i < n; i++) {
            l[i] = new ArrayList<>();
        }

        for (int i = 0; i < n; i++) {
            int a = find(i);
            l[a].add(i);
            p.add(a);
        }

        int max = 0;
        Iterator<Integer> it = p.iterator();
        int[] clr;
        while (it.hasNext()) {
            int a = it.next();
            max = 0;
            clr = new int[k];
            for (int i = 0; i < l[a].size(); i++) {
                max = Math.max(++clr[color[l[a].get(i)]],max);
            }
            ans += size[a]-max;

        }

        out.println(ans);
    }

}


import java.io.*;
import java.util.*;

public class C {

    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;

    public static void main(String[] args) throws IOException {
        try {
            in = new BufferedReader(new FileReader("unequal.in"));
            out = new PrintWriter(new File("unequal.out"));
        } catch (Exception e) {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(new OutputStreamWriter(System.out));
        }
        tok = new StringTokenizer("");
        new C().solve();
        out.flush();
        out.close();
    }

    String nextTok() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine());
        }
        return tok.nextToken();
    }

    String nextLine() throws IOException {
        return in.readLine();
    }

    int nextInt() throws IOException {
        return Integer.parseInt(nextTok());
    }

    long nextLong() throws IOException {
        return Long.parseLong(nextTok());
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(nextTok());
    }

    class Pair implements Comparable<Pair>{
        int a;
        int b;

        Pair(int a, int b) {
            this.a = a;
            this.b = b;
        }

        @Override
        public int compareTo(Pair o) {
            return 0;
        }
    }

    int[] dsu;
    int[] size;

    int find(int a) {
        if (dsu[a] != a) return dsu[a] = find(dsu[a]);
        return dsu[a];
    }

    void union(int a, int b) {
        a = find(a);
        b = find(b);
        if (a != b) {
            if ((int)Math.round(Math.random()) == 1) {
                dsu[a] = b;
                size[b] += size[a];
            } else {
                dsu[b] = a;
                size[a] += size[b];
            }
        }
    }

    void solve() throws IOException {
        int n = nextInt();
        int m = nextInt();
        int k = nextInt();
        dsu = new int[n];
        size = new int[n];
        int color[] = new int[n];
        for (int i = 0; i < n; i++) {
            color[i] = nextInt()-1;
            dsu[i] = i;
            size[i] = 1;
        }
        int ans = 0;
        for (int i = 0; i < m; i++) {
            int a = nextInt()-1;
            int b = nextInt()-1;
            union(a,b);
        }

        HashSet<Integer> p = new HashSet<>();
        ArrayList<Integer>[] l = new ArrayList[n];

        for (int i = 0; i < n; i++) {
            l[i] = new ArrayList<>();
        }

        for (int i = 0; i < n; i++) {
            int a = find(i);
            l[a].add(i);
            p.add(a);
        }

        int max = 0;
        Iterator<Integer> it = p.iterator();
//        int[] clr;
        while (it.hasNext()) {
            int a = it.next();
            max = 0;
            HashMap<Integer,Integer> mp = new HashMap<>();
//            clr = new int[k];
            for (int v: l[a]) {
                mp.put(color[v],mp.getOrDefault(color[v],0)+1);
                max = Math.max(mp.get(color[v]),max);
            }
            ans += size[a]-max;

        }

        out.println(ans);
    }

}


import java.io.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.StringTokenizer;

public class C {

    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;

    public static void main(String[] args) throws IOException {
        try {
            in = new BufferedReader(new FileReader("unequal.in"));
            out = new PrintWriter(new File("unequal.out"));
        } catch (Exception e) {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(new OutputStreamWriter(System.out));
        }
        tok = new StringTokenizer("");
        new C().solve();
        out.flush();
        out.close();
    }

    String nextTok() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine());
        }
        return tok.nextToken();
    }

    String nextLine() throws IOException {
        return in.readLine();
    }

    int nextInt() throws IOException {
        return Integer.parseInt(nextTok());
    }

    long nextLong() throws IOException {
        return Long.parseLong(nextTok());
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(nextTok());
    }

    class Pair implements Comparable<Pair>{
        int a;
        int b;

        Pair(int a, int b) {
            this.a = a;
            this.b = b;
        }

        @Override
        public int compareTo(Pair o) {
            return 0;
        }
    }

    int[] dsu;
    int[] size;

    int find(int a) {
        if (dsu[a] != a) return dsu[a] = find(dsu[a]);
        return dsu[a];
    }

    void union(int a, int b) {
        a = find(a);
        b = find(b);
        if (a != b) {
            if ((int)Math.round(Math.random()) == 1) {
                dsu[a] = b;
                size[b] += size[a];
            } else {
                dsu[b] = a;
                size[a] += size[b];
            }
        }
    }

    void solve() throws IOException {
        int n = nextInt();
        int m = nextInt();
        int k = nextInt();
        dsu = new int[n+1];
        size = new int[n+1];
        int color[] = new int[n+1];
        for (int i = 1; i <= n; i++) {
            color[i] = nextInt();
            dsu[i] = i;
            size[i] = 1;
        }
        int ans = 0;
        for (int i = 0; i < m; i++) {
            int a = nextInt();
            int b = nextInt();
            union(a,b);
        }

        int[][] cntColors = new int[n+1][];
        HashSet<Integer> p = new HashSet<>();
        for (int i = 1; i <= n; i++) {
            int a = find(i);
            if (cntColors[a] == null) {
                cntColors[a] = new int[k+1];
            }
            cntColors[a][color[i]]++;
            p.add(a);
        }

        for (int a: p) {
            Arrays.sort(cntColors[a]);
//            out.println(a+" "+size[a]+" "+cntColors[a][k]);
            ans += size[a]-cntColors[a][k];
        }
        out.println(ans);
    }

}


import java.io.*;
import java.util.*;

public class C {

    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;

    public static void main(String[] args) throws IOException {
        try {
            in = new BufferedReader(new FileReader("unequal.in"));
            out = new PrintWriter(new File("unequal.out"));
        } catch (Exception e) {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(new OutputStreamWriter(System.out));
        }
        tok = new StringTokenizer("");
        new C().solve();
        out.flush();
        out.close();
    }

    String nextTok() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine());
        }
        return tok.nextToken();
    }

    String nextLine() throws IOException {
        return in.readLine();
    }

    int nextInt() throws IOException {
        return Integer.parseInt(nextTok());
    }

    long nextLong() throws IOException {
        return Long.parseLong(nextTok());
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(nextTok());
    }

    class Pair implements Comparable<Pair>{
        int a;
        int b;

        Pair(int a, int b) {
            this.a = a;
            this.b = b;
        }

        @Override
        public int compareTo(Pair o) {
            return 0;
        }
    }

    int[] dsu;
    int[] size;

    int find(int a) {
        if (dsu[a] != a) return dsu[a] = find(dsu[a]);
        return dsu[a];
    }

    void union(int a, int b) {
        a = find(a);
        b = find(b);
        if (a != b) {
            if ((int)Math.round(Math.random()) == 1) {
                dsu[a] = b;
                size[b] += size[a];
            } else {
                dsu[b] = a;
                size[a] += size[b];
            }
        }
    }

    void solve() throws IOException {
        int n = nextInt();
        int m = nextInt();
        int k = nextInt();
        dsu = new int[n];
        size = new int[n];
        int color[] = new int[n];
        for (int i = 0; i < n; i++) {
            color[i] = nextInt()-1;
            dsu[i] = i;
            size[i] = 1;
        }
        int ans = 0;
        for (int i = 0; i < m; i++) {
            int a = nextInt()-1;
            int b = nextInt()-1;
            union(a,b);
        }

        HashSet<Integer> p = new HashSet<>();
        ArrayList<Integer>[] l = new ArrayList[n];

        for (int i = 0; i < n; i++) {
            l[i] = new ArrayList<>();
        }

        for (int i = 0; i < n; i++) {
            int a = find(i);
            l[a].add(i);
            p.add(a);
        }

        int max = 0;
        Iterator<Integer> it = p.iterator();
        int[] clr;
        while (it.hasNext()) {
            int a = it.next();
            clr = new int[k];
            for (int i = 0; i < l[a].size(); i++) {
                max = Math.max(++clr[l[a].get(i)],max);
            }
            ans += size[a]-max;

        }

        out.println(ans);
    }

}


import java.io.*;
import java.util.*;

public class C {

    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;

    public static void main(String[] args) throws IOException {
        try {
            in = new BufferedReader(new FileReader("unequal.in"));
            out = new PrintWriter(new File("unequal.out"));
        } catch (Exception e) {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(new OutputStreamWriter(System.out));
        }
        tok = new StringTokenizer("");
        new C().solve();
        out.flush();
        out.close();
    }

    String nextTok() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine());
        }
        return tok.nextToken();
    }

    String nextLine() throws IOException {
        return in.readLine();
    }

    int nextInt() throws IOException {
        return Integer.parseInt(nextTok());
    }

    long nextLong() throws IOException {
        return Long.parseLong(nextTok());
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(nextTok());
    }

    class Pair implements Comparable<Pair>{
        int a;
        int b;

        Pair(int a, int b) {
            this.a = a;
            this.b = b;
        }

        @Override
        public int compareTo(Pair o) {
            return 0;
        }
    }

    int[] dsu;
    int[] size;

    int find(int a) {
        if (dsu[a] != a) return dsu[a] = find(dsu[a]);
        return dsu[a];
    }

    void union(int a, int b) {
        a = find(a);
        b = find(b);
        if (a != b) {
            if ((int)Math.round(Math.random()) == 1) {
                dsu[a] = b;
                size[b] += size[a];
            } else {
                dsu[b] = a;
                size[a] += size[b];
            }
        }
    }

    void solve() throws IOException {
        int n = nextInt();
        int m = nextInt();
        int k = nextInt();
        dsu = new int[n];
        size = new int[n];
        int color[] = new int[n];
        for (int i = 0; i < n; i++) {
            color[i] = nextInt()-1;
            dsu[i] = i;
            size[i] = 1;
        }
        int ans = 0;
        for (int i = 0; i < m; i++) {
            int a = nextInt()-1;
            int b = nextInt()-1;
            union(a,b);
        }

        HashSet<Integer> p = new HashSet<>();
        ArrayList<Integer>[] l = new ArrayList[n];

        for (int i = 0; i < n; i++) {
            l[i] = new ArrayList<>();
        }

        for (int i = 0; i < n; i++) {
            int a = find(i);
            l[a].add(i);
            p.add(a);
        }

        int max = 0;
        Iterator<Integer> it = p.iterator();
        int[][] clr = new int[p.size()][k];
        int id = 0;
        while (it.hasNext()) {
            int a = it.next();
            max = 0;

            for (int i = 0; i < l[a].size(); i++) {
                max = Math.max(++clr[id][color[l[a].get(i)]],max);
            }
            ++id;
            ans += size[a]-max;

        }

        out.println(ans);
    }

}


import java.io.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.StringTokenizer;

public class C {

    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;

    public static void main(String[] args) throws IOException {
        try {
            in = new BufferedReader(new FileReader("unequal.in"));
            out = new PrintWriter(new File("unequal.out"));
        } catch (Exception e) {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(new OutputStreamWriter(System.out));
        }
        tok = new StringTokenizer("");
        new C().solve();
        out.flush();
        out.close();
    }

    String nextTok() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine());
        }
        return tok.nextToken();
    }

    String nextLine() throws IOException {
        return in.readLine();
    }

    int nextInt() throws IOException {
        return Integer.parseInt(nextTok());
    }

    long nextLong() throws IOException {
        return Long.parseLong(nextTok());
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(nextTok());
    }

    class Pair implements Comparable<Pair>{
        int a;
        int b;

        Pair(int a, int b) {
            this.a = a;
            this.b = b;
        }

        @Override
        public int compareTo(Pair o) {
            return 0;
        }
    }

    int[] dsu;
    int[] size;

    int find(int a) {
        if (dsu[a] != a) return dsu[a] = find(dsu[a]);
        return dsu[a];
    }

    void union(int a, int b) {
        a = find(a);
        b = find(b);
        if (a != b) {
            if ((int)Math.round(Math.random()) == 1) {
                dsu[a] = b;
                size[b] += size[a];
            } else {
                dsu[b] = a;
                size[a] += size[b];
            }
        }
    }

    void solve() throws IOException {
        int n = nextInt();
        int m = nextInt();
        int k = nextInt();
        dsu = new int[n+1];
        size = new int[n+1];
        int color[] = new int[n+1];
        for (int i = 1; i <= n; i++) {
            color[i] = nextInt();
            dsu[i] = i;
            size[i] = 1;
        }
        int ans = 0;
        for (int i = 0; i < m; i++) {
            int a = nextInt();
            int b = nextInt();
            union(a,b);
        }

        int[][] cntColors = new int[n+1][k+1];
        HashSet<Integer> p = new HashSet<>();
        for (int i = 1; i <= n; i++) {
            int a = find(i);
            cntColors[a][color[i]]++;
            p.add(a);
        }

        for (int a: p) {
            Arrays.sort(cntColors[a]);
//            out.println(a+" "+size[a]+" "+cntColors[a][k]);
            ans += size[a]-cntColors[a][k];
        }
        out.println(ans);
    }

}


import java.io.*;
import java.util.*;

public class C {

    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;

    public static void main(String[] args) throws IOException {
        try {
            in = new BufferedReader(new FileReader("unequal.in"));
            out = new PrintWriter(new File("unequal.out"));
        } catch (Exception e) {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(new OutputStreamWriter(System.out));
        }
        tok = new StringTokenizer("");
        new C().solve();
        out.flush();
        out.close();
    }

    String nextTok() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine());
        }
        return tok.nextToken();
    }

    String nextLine() throws IOException {
        return in.readLine();
    }

    int nextInt() throws IOException {
        return Integer.parseInt(nextTok());
    }

    long nextLong() throws IOException {
        return Long.parseLong(nextTok());
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(nextTok());
    }

    class Pair implements Comparable<Pair>{
        int a;
        int b;

        Pair(int a, int b) {
            this.a = a;
            this.b = b;
        }

        @Override
        public int compareTo(Pair o) {
            return 0;
        }
    }

    int[] dsu;
    int[] size;

    int find(int a) {
        if (dsu[a] != a) return dsu[a] = find(dsu[a]);
        return dsu[a];
    }

    void union(int a, int b) {
        a = find(a);
        b = find(b);
        if (a != b) {
            if ((int)Math.round(Math.random()) == 1) {
                dsu[a] = b;
                size[b] += size[a];
            } else {
                dsu[b] = a;
                size[a] += size[b];
            }
        }
    }

    void solve() throws IOException {
        int n = nextInt();
        int m = nextInt();
        int k = nextInt();
        dsu = new int[n];
        size = new int[n];
        int color[] = new int[n];
        for (int i = 0; i < n; i++) {
            color[i] = nextInt()-1;
            dsu[i] = i;
            size[i] = 1;
        }
        int ans = 0;
        for (int i = 0; i < m; i++) {
            int a = nextInt()-1;
            int b = nextInt()-1;
            union(a,b);
        }

//        int[][] cntColors = new int[n][];
        HashSet<Integer> p = new HashSet<>();
        HashMap<Integer, ArrayList<Integer>> componentMap = new HashMap<Integer, ArrayList<Integer>>();
        for (int i = 0; i < n; i++) {
            int a = find(i);
//            if (cntColors[a] == null) {
//                cntColors[a] = new int[k];
//            }
//            cntColors[a][color[i]]++;
            if (componentMap.containsKey(a)) {
                componentMap.get(a).add(i);
            } else {
                componentMap.put(a,new ArrayList<>());
                componentMap.get(a).add(i);
            }

        }

        for (Map.Entry<Integer,ArrayList<Integer>> el: componentMap.entrySet()) {
            int max = 0;
            int[] clr = new int[k];
            for (int i = 0; i < el.getValue().size(); i++) {
                if (++clr[color[el.getValue().get(i)]] > max) {
                    max = clr[color[el.getValue().get(i)]];
                }
            }
            ans += size[el.getKey()] - max;
        }

        out.println(ans);
    }

}


import java.io.*;
import java.util.*;

public class C {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(br.readLine());
		int n = Integer.parseInt(st.nextToken());
		int m = Integer.parseInt(st.nextToken());
		int k = Integer.parseInt(st.nextToken());
		int sock[] = new int[n + 1];
		ArrayList<Integer> [] adj = new ArrayList[n+1];
		st = new StringTokenizer(br.readLine());
		for (int i = 1; i <= n; i++) {
			sock[i] = Integer.parseInt(st.nextToken());
			adj[i] = new ArrayList<Integer>();
		}
		int l, r = 0;
		for (int i = 1; i <= m; i++) {
			st = new StringTokenizer(br.readLine());
			l = Integer.parseInt(st.nextToken());
			r = Integer.parseInt(st.nextToken());
			adj[l].add(r);
			adj[r].add(l);
		}
		int changes = 0;
		boolean visited[] = new boolean[n + 1];
		Map<Integer, Integer> col = new HashMap<>();
		Stack<Integer> stk = new Stack<>();
		for (int i = 1; i <= n; i++) {
			if (visited[i]) {
				continue;
			}
			stk.push(i);
			visited[i] = true;
			int max = 0;
			col.clear();
			while (!stk.isEmpty()) {
				int x = stk.pop();
				if(col.containsKey(sock[x])) {
					col.put(sock[x], col.get(sock[x])+1);
				}
				else {
					col.put(sock[x], 1);
				}
				max = Math.max(max, col.get(sock[x]));
				changes++;
				for (Integer j : adj[x]) {
					if (!visited[j]) {
						visited[j] = true;
						stk.push(j);
					}
				}
			}
			changes -= max;
		}
		System.out.println(changes);
		br.close();
	}
}


import java.util.*;

public class C {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int m = in.nextInt();
		int k = in.nextInt();
		int sock[] = new int[n + 1];
		Map<Integer, ArrayList<Integer>> adj = new TreeMap<>();
		adj.put(0, new ArrayList<Integer>());
		for (int i = 1; i <= n; i++) {
			sock[i] = in.nextInt();
			adj.put(i, new ArrayList<Integer>());
		}
		int l, r = 0;
		for (int i = 1; i <= m; i++) {
			l = in.nextInt();
			r = in.nextInt();
			adj.get(l).add(r);
			adj.get(r).add(l);
		}
		int changes = 0;
		boolean visited[] = new boolean[n + 1];
		for (int i = 1; i <= n; i++) {
			if (visited[i]) {
				continue;
			}
			int col[] = new int[k + 1];
			Stack<Integer> stk = new Stack<>();
			stk.push(i);
			visited[i] = true;
			while (!stk.isEmpty()) {
				int x = stk.pop();
				col[sock[x]]++;
				for (Integer j : adj.get(x)) {
					if (!visited[j]) {
						visited[j] = true;
						stk.push(j);
					}
				}
			}
			int max = 0;
			for(int j = 1; j <= k; j++) {
				if (col[j] > max) {
					max = col[j];
				}
				changes += col[j];
			}
			changes -= max;
		}
		System.out.println(changes);
		in.close();
	}
}


import java.util.*;

public class C {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int m = in.nextInt();
		int k = in.nextInt();
		int sock[] = new int[n + 1];
		Map<Integer, List<Integer>> adj = new HashMap<>();
		adj.put(0, new ArrayList<Integer>());
		for (int i = 1; i <= n; i++) {
			sock[i] = in.nextInt();
			adj.put(i, new ArrayList<Integer>());
		}
		int l, r = 0;
		for (int i = 1; i <= m; i++) {
			l = in.nextInt();
			r = in.nextInt();
			adj.get(l).add(r);
			adj.get(r).add(l);
		}
		int changes = 0;
		boolean visited[] = new boolean[n + 1];
		int col[] = new int[k + 1];
		for (int i = 1; i <= n; i++) {
			if (visited[i]) {
				continue;
			}
			Stack<Integer> stk = new Stack<>();
			stk.push(i);
			visited[i] = true;
			while (!stk.isEmpty()) {
				int x = stk.pop();
				col[sock[x]]++;
				for (Integer j : adj.get(x)) {
					if (!visited[j]) {
						visited[j] = true;
						stk.push(j);
					}
				}
			}
			int max = 0;
			for(int j = 1; j <= k; j++) {
				if (col[j] > max) {
					max = col[j];
				}
				changes += col[j];
				col[j] = 0;
			}
			changes -= max;
		}
		System.out.println(changes);
		in.close();
	}
}


import java.util.*;

public class C {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int m = in.nextInt();
		int k = in.nextInt();
		int sock[] = new int[n + 1];
		Map<Integer, List<Integer>> adj = new HashMap<>();
		adj.put(0, new ArrayList<Integer>());
		for (int i = 1; i <= n; i++) {
			sock[i] = in.nextInt();
			adj.put(i, new ArrayList<Integer>());
		}
		int l, r = 0;
		for (int i = 1; i <= m; i++) {
			l = in.nextInt();
			r = in.nextInt();
			adj.get(l).add(r);
			adj.get(r).add(l);
		}
		int changes = 0;
		boolean visited[] = new boolean[n + 1];
		//int col[] = new int[k + 1];
		Map<Integer, Integer> col2 = new HashMap<>();
		Stack<Integer> stk = new Stack<>();
		for (int i = 1; i <= n; i++) {
			if (visited[i]) {
				continue;
			}
			stk.push(i);
			visited[i] = true;
			int max = 0;
			col2.clear();
			while (!stk.isEmpty()) {
				int x = stk.pop();
				if(col2.containsKey(sock[x])) {
					col2.put(sock[x], col2.get(sock[x])+1);
				}
				else {
					col2.put(sock[x], 1);
				}
				if (col2.get(sock[x]) > max) {
					max = col2.get(sock[x]);
				}
				changes++;
				//col[sock[x]]++;
				for (Integer j : adj.get(x)) {
					if (!visited[j]) {
						visited[j] = true;
						stk.push(j);
					}
				}
			}
//			for(int j = 1; j <= k; j++) {
//				if (col[j] > max) {
//					max = col[j];
//				}
//				changes += col[j];
//				col[j] = 0;
//			}
			changes -= max;
		}
		System.out.println(changes);
		in.close();
	}
}


import java.util.*;

public class C {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int m = in.nextInt();
		int k = in.nextInt();
		int sock[] = new int[n + 1];
		ArrayList<Integer> [] adj = new ArrayList[n+1];
		for (int i = 1; i <= n; i++) {
			sock[i] = in.nextInt();
			adj[i] = new ArrayList<Integer>();
		}
		int l, r = 0;
		for (int i = 1; i <= m; i++) {
			l = in.nextInt();
			r = in.nextInt();
			adj[l].add(r);
			adj[r].add(l);
		}
		int changes = 0;
		boolean visited[] = new boolean[n + 1];
		Map<Integer, Integer> col = new HashMap<>();
		Stack<Integer> stk = new Stack<>();
		for (int i = 1; i <= n; i++) {
			if (visited[i]) {
				continue;
			}
			stk.push(i);
			visited[i] = true;
			int max = 0;
			col.clear();
			while (!stk.isEmpty()) {
				int x = stk.pop();
				if(col.containsKey(sock[x])) {
					col.put(sock[x], col.get(sock[x])+1);
				}
				else {
					col.put(sock[x], 1);
				}
				max = Math.max(max, col.get(sock[x]));
				changes++;
				for (Integer j : adj[x]) {
					if (!visited[j]) {
						visited[j] = true;
						stk.push(j);
					}
				}
			}
			changes -= max;
		}
		System.out.println(changes);
		in.close();
	}
}


import java.util.*;

public class C {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int m = in.nextInt();
		int k = in.nextInt();
		int sock[] = new int[n + 1];
		Map<Integer, Set<Integer>> adj = new HashMap<>();
		adj.put(0, new HashSet<Integer>());
		for (int i = 1; i <= n; i++) {
			sock[i] = in.nextInt();
			adj.put(i, new HashSet<Integer>());
		}
		int l, r = 0;
		for (int i = 1; i <= m; i++) {
			l = in.nextInt();
			r = in.nextInt();
			adj.get(l).add(r);
			adj.get(r).add(l);
		}
		int changes = 0;
		boolean visited[] = new boolean[n + 1];
		for (int i = 1; i <= n; i++) {
			if (visited[i]) {
				continue;
			}
			int col[] = new int[k + 1];
			Stack<Integer> stk = new Stack<>();
			stk.push(i);
			visited[i] = true;
			while (!stk.isEmpty()) {
				int x = stk.pop();
				col[sock[x]]++;
				for (Integer j : adj.get(x)) {
					if (!visited[j]) {
						visited[j] = true;
						stk.push(j);
					}
				}
			}
			int max = 0;
			for(int j = 1; j <= k; j++) {
				if (col[j] > max) {
					max = col[j];
				}
				changes += col[j];
			}
			changes -= max;
		}
		System.out.println(changes);
		in.close();
	}
}


import java.util.*;

public class C {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int m = in.nextInt();
		int k = in.nextInt();
		int sock[] = new int[n + 1];
		Map<Integer, List<Integer>> adj = new HashMap<>();
		for (int i = 1; i <= n; i++) {
			sock[i] = in.nextInt();
			adj.put(i, new ArrayList<Integer>());

		}
		int l, r = 0;
		for (int i = 1; i <= m; i++) {
			l = in.nextInt();
			r = in.nextInt();
			adj.get(l).add(r);
			adj.get(r).add(l);
		}
		int changes = 0;
		boolean visited[] = new boolean[n + 1];
		Map<Integer, Integer> col = new HashMap<>();
		Stack<Integer> stk = new Stack<>();
		for (int i = 1; i <= n; i++) {
			if (visited[i]) {
				continue;
			}
			stk.push(i);
			visited[i] = true;
			int max = 0;
			col.clear();
			while (!stk.isEmpty()) {
				int x = stk.pop();
				if(col.containsKey(sock[x])) {
					col.put(sock[x], col.get(sock[x])+1);
				}
				else {
					col.put(sock[x], 1);
				}
				if (col.get(sock[x]) > max) {
					max = col.get(sock[x]);
				}
				changes++;
				for (Integer j : adj.get(x)) {
					if (!visited[j]) {
						visited[j] = true;
						stk.push(j);
					}
				}
			}
			changes -= max;
		}
		System.out.println(changes);
		in.close();
	}
}


import java.util.*;

public class C {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int m = in.nextInt();
		int k = in.nextInt();
		int sock[] = new int[n + 1];
		Map<Integer, Set<Integer>> adj = new HashMap<>();
		adj.put(0, new HashSet<Integer>());
		for (int i = 1; i <= n; i++) {
			sock[i] = in.nextInt();
			adj.put(i, new HashSet<Integer>());
		}
		int l, r = 0;
		for (int i = 1; i <= m; i++) {
			l = in.nextInt();
			r = in.nextInt();
			adj.get(l).add(r);
			adj.get(r).add(l);
		}
		int changes = 0;
		boolean visited[] = new boolean[n + 1];
		//int col[] = new int[k + 1];
		Map<Integer, Integer> col2 = new HashMap<>();
		Stack<Integer> stk = new Stack<>();
		for (int i = 1; i <= n; i++) {
			if (visited[i]) {
				continue;
			}
			stk.push(i);
			visited[i] = true;
			int max = 0;
			col2.clear();
			while (!stk.isEmpty()) {
				int x = stk.pop();
				if(col2.containsKey(sock[x])) {
					col2.put(sock[x], col2.get(sock[x])+1);
				}
				else {
					col2.put(sock[x], 1);
				}
				if (col2.get(sock[x]) > max) {
					max = col2.get(sock[x]);
				}
				changes++;
				//col[sock[x]]++;
				for (Integer j : adj.get(x)) {
					if (!visited[j]) {
						visited[j] = true;
						stk.push(j);
					}
				}
			}
//			for(int j = 1; j <= k; j++) {
//				if (col[j] > max) {
//					max = col[j];
//				}
//				changes += col[j];
//				col[j] = 0;
//			}
			changes -= max;
		}
		System.out.println(changes);
		in.close();
	}
}


import java.util.*;

public class C {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int m = in.nextInt();
		int k = in.nextInt();
		int sock[] = new int[n + 1];
		Map<Integer, Set<Integer>> adj = new TreeMap<>();
		adj.put(0, new HashSet<Integer>());
		for (int i = 1; i <= n; i++) {
			sock[i] = in.nextInt();
			adj.put(i, new HashSet<Integer>());
		}
		int l, r = 0;
		for (int i = 1; i <= m; i++) {
			l = in.nextInt();
			r = in.nextInt();
			adj.get(l).add(r);
			adj.get(r).add(l);
		}
		int changes = 0;
		boolean visited[] = new boolean[n + 1];
		for (int i = 1; i <= n; i++) {
			if (visited[i]) {
				continue;
			}
			int col[] = new int[k + 1];
			Stack<Integer> stk = new Stack<>();
			stk.push(i);
			visited[i] = true;
			while (!stk.isEmpty()) {
				int x = stk.pop();
				col[sock[x]]++;
				for (Integer j : adj.get(x)) {
					if (!visited[j]) {
						visited[j] = true;
						stk.push(j);
					}
				}
			}
			int max = 0;
			for(int j = 1; j <= k; j++) {
				if (col[j] > max) {
					max = col[j];
				}
				changes += col[j];
			}
			changes -= max;
		}
		System.out.println(changes);
		in.close();
	}
}


import java.util.ArrayList;
import java.util.Scanner;
import java.util.Stack;

public class C {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int m = in.nextInt();
		int k = in.nextInt();
		int sock[] = new int[n + 1];
		ArrayList<ArrayList<Integer>> adj = new ArrayList<>();
		adj.add(new ArrayList<Integer>());
		for (int i = 1; i <= n; i++) {
			sock[i] = in.nextInt();
			adj.add(new ArrayList<Integer>());
		}
		int l[] = new int[m + 1];
		int r[] = new int[m + 1];
		for (int i = 1; i <= m; i++) {
			l[i] = in.nextInt();
			r[i] = in.nextInt();
			adj.get(l[i]).add(r[i]);
			adj.get(r[i]).add(l[i]);
		}
		int changes = 0;
		boolean visited[] = new boolean[n + 1];
		for (int i = 1; i <= n; i++) {
			if (visited[i]) {
				continue;
			}
			int col[] = new int[k + 1];
			Stack<Integer> stk = new Stack<>();
			stk.push(i);
			visited[i] = true;
			while (!stk.isEmpty()) {
				int x = stk.pop();
				col[sock[x]]++;
				for (Integer j : adj.get(x)) {
					if (!visited[j]) {
						visited[j] = true;
						stk.push(j);
					}
				}
			}
			int max = 0;
			for(int j = 1; j <= k; j++) {
				if (col[j] > max) {
					max = col[j];
				}
				changes += col[j];
			}
			changes -= max;
		}
		System.out.println(changes);
		in.close();
	}

}


import java.util.*;

public class C {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int m = in.nextInt();
		int k = in.nextInt();
		int sock[] = new int[n + 1];
		Map<Integer, List<Integer>> adj = new HashMap<>();
		adj.put(0, new ArrayList<Integer>());
		for (int i = 1; i <= n; i++) {
			sock[i] = in.nextInt();
			adj.put(i, new ArrayList<Integer>());
		}
		int l, r = 0;
		for (int i = 1; i <= m; i++) {
			l = in.nextInt();
			r = in.nextInt();
			adj.get(l).add(r);
			adj.get(r).add(l);
		}
		int changes = 0;
		boolean visited[] = new boolean[n + 1];
		for (int i = 1; i <= n; i++) {
			if (visited[i]) {
				continue;
			}
			int col[] = new int[k + 1];
			Stack<Integer> stk = new Stack<>();
			stk.push(i);
			visited[i] = true;
			while (!stk.isEmpty()) {
				int x = stk.pop();
				col[sock[x]]++;
				for (Integer j : adj.get(x)) {
					if (!visited[j]) {
						visited[j] = true;
						stk.push(j);
					}
				}
			}
			int max = 0;
			for(int j = 1; j <= k; j++) {
				if (col[j] > max) {
					max = col[j];
				}
				changes += col[j];
			}
			changes -= max;
		}
		System.out.println(changes);
		in.close();
	}
}


import java.util.*;

public class C {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int m = in.nextInt();
		int k = in.nextInt();
		int sock[] = new int[n + 1];
		Map<Integer, List<Integer>> adj = new HashMap<>();
		Map<Integer, Set<Integer>> adj2 = new HashMap<>();

		for (int i = 1; i <= n; i++) {
			sock[i] = in.nextInt();
			adj.put(i, new ArrayList<Integer>());
			adj2.put(i, new HashSet<Integer>());
		}
		int l, r = 0;
		for (int i = 1; i <= m; i++) {
			l = in.nextInt();
			r = in.nextInt();
			adj2.get(l).add(r);
			adj2.get(r).add(l);
		}
		for (int i = 1; i <=n; i++) {
			for(int j : adj2.get(i)) {
				adj.get(i).add(j);
			}
		}

		int changes = 0;
		boolean visited[] = new boolean[n + 1];
		Map<Integer, Integer> col = new HashMap<>();
		Stack<Integer> stk = new Stack<>();
		for (int i = 1; i <= n; i++) {
			if (visited[i]) {
				continue;
			}
			stk.push(i);
			visited[i] = true;
			int max = 0;
			col.clear();
			while (!stk.isEmpty()) {
				int x = stk.pop();
				if(col.containsKey(sock[x])) {
					col.put(sock[x], col.get(sock[x])+1);
				}
				else {
					col.put(sock[x], 1);
				}
				if (col.get(sock[x]) > max) {
					max = col.get(sock[x]);
				}
				changes++;
				for (Integer j : adj.get(x)) {
					if (!visited[j]) {
						visited[j] = true;
						stk.push(j);
					}
				}
			}
			changes -= max;
		}
		System.out.println(changes);
		in.close();
	}
}


import java.util.*;

public class proC{
    public static void main(String[] args){
        Scanner in=new Scanner(System.in);
        int n=in.nextInt(),m=in.nextInt(),k=in.nextInt();
        int[] socks=new int[n];
        int[] trees=new int[n];
        for(int i=0;i<n;i++){
            socks[i]=in.nextInt();
            trees[i]=i;
        }
        for(int i=0;i<m;i++){
            int a=in.nextInt()-1,b=in.nextInt()-1;
            while(trees[a]!=a){
                trees[a]=trees[trees[a]];a=trees[a];
            }
            while(trees[b]!=b){
                trees[b]=trees[trees[b]];b=trees[b];
            }
            trees[a]=b;
        }
        List<Set<Integer>> list=new ArrayList<Set<Integer>>();
        for(int i=0;i<n;i++){
            int a=trees[i];
            while(trees[a]!=a){
                trees[a]=trees[trees[a]];a=trees[a];
            }
            boolean find=false;
            for(Set<Integer> set:list){
                if(set.contains(a)){
                    set.add(i);find=true;break;
                }
            }
            if(!find){
                Set<Integer> set=new HashSet<Integer>();
                set.add(a);set.add(i);list.add(set);
            }
        }
        int res=0;
        for(Set<Integer> set:list){
            Map<Integer,Integer> map=new HashMap<Integer,Integer>();
            for(int i:set){
                int color=socks[i];
                map.put(color,map.getOrDefault(color,0)+1);
            }
            int max=0;
            for(int key:map.keySet()){
                max=Math.max(max,map.get(key));
            }
            res+=set.size()-max;
        }
        System.out.println(res);
    }
}


import java.util.*;

public class proC{
    public staic void main(String[] args){
        Scanner in=new Scanner(System.in);
        int n=in.nextInt(),m=in.nextInt(),k=in.nextInt();
        List<Integer>[] graph=(ArrayList<Integer>[])new ArrayList[n+1];
        // int[] socks=new int[n+1];
        // for(int i=1;i<=n;i++){
        //     socks[i]=in.nextInt();
        //     graph[i]=new ArrayList<Integer>();
        // }
        // for(int i=1;i<=m;i++){
        //     int a=in.nextInt(),b=in.nextInt();
        //     graph[a].add(b);graph[b].add(a);
        // }
        // boolean[] visited=new boolean[n+1];
        // int change=0;
        // for(int i=1;i<=n;i++){
        //     if(visited[i])continue;
        //     Queue<Integer> q=new LinkedList<Integer>();
        //     Map<Integer,Integer> map=new HashMap<Integer,Integer>();
        //     q.add(i);visited[i]=true;
        //     int max=0;
        //     while(!q.isEmpty()){
        //         int x=q.remove();
        //         change++;
        //         map.put(socks[x],map.getOrDefault(socks[x],0)+1);
        //         max=Math.max(max,map.get(socks[x]));
        //     }
        //     change-=max;
        // }
        System.out.println(1);
    }
}


import java.util.*;

public class proC{
    public staic void main(String[] args){
        Scanner in=new Scanner(System.in);
        int n=in.nextInt(),m=in.nextInt(),k=in.nextInt();
        List<Integer>[] graph=(ArrayList<Integer>)new List[n+1];
        int[] socks=new int[n+1];
        for(int i=1;i<=n;i++){
            socks[i]=in.nextInt();
            graph[i]=new ArrayList<Integer>();
        }
        for(int i=1;i<=m;i++){
            int a=in.nextInt(),b=in.nextInt();
            graph[a].add(b);graph[b].add(a);
        }
        boolean[] visited=new boolean[n+1];
        int change=0;
        for(int i=1;i<=n;i++){
            if(visited[i])continue;
            Queue<Integer> q=new LinkedList<Integer>();
            Map<Integer,Integer> map=new HashMap<Integer,Integer>();
            q.add(i);visited[i]=true;
            int max=0;
            while(!q.isEmpty()){
                int x=q.remove();
                change++;
                map.put(socks[x],map.getOrDefault(socks[x],0)+1);
                max=Math.max(max,map.get(socks[x]));
            }
            change-=max;
        }
        System.out.println(change);
    }
}


import java.util.*;

public class proC{
    public static void main(String[] args){
        Scanner in=new Scanner(System.in);
        int n=in.nextInt(),m=in.nextInt(),k=in.nextInt();
        int[] socks=new int[n];
        int[] trees=new int[n];
        for(int i=0;i<n;i++){
            socks[i]=in.nextInt();
            trees[i]=i;
        }
        for(int i=0;i<m;i++){
            int a=in.nextInt(),b=in.nextInt();
            while(trees[a]!=a){
                trees[a]=trees[trees[a]];a=trees[a];
            }
            while(trees[b]!=b){
                trees[b]=trees[trees[b]];b=trees[b];
            }
            trees[a]=b;
        }
        List<Set<Integer>> list=new ArrayList<Set<Integer>>();
        for(int i=0;i<n;i++){
            int a=trees[i];
            while(trees[a]!=a){
                trees[a]=trees[trees[a]];a=trees[a];
            }
            boolean find=false;
            for(Set<Integer> set:list){
                if(set.contains(a)){
                    set.add(i);find=true;break;
                }
            }
            if(!find){
                Set<Integer> set=new HashSet<Integer>();
                set.add(a);set.add(i);list.add(set);
            }
        }
        int res=0;
        for(Set<Integer> set:list){
            Map<Integer,Integer> map=new HashMap<Integer,Integer>();
            for(int i:set){
                int color=socks[i];
                map.put(color,map.getOrDefault(color,0)+1);
            }
            int max=0;
            for(int key:map.keySet()){
                max=Math.max(max,map.get(key));
            }
            res+=set.size()-max;
        }
        System.out.println(res);
    }
}


import java.util.*;

public class proC{
    public staic void main(String[] args){
        Scanner in=new Scanner(System.in);
        int n=in.nextInt(),m=in.nextInt(),k=in.nextInt();
        // ArrayList<Integer>[] graph=new ArrayList[n+1];
        int[] socks=new int[n+1];
        for(int i=1;i<=n;i++){
            socks[i]=in.nextInt();
            // graph[i]=new ArrayList<Integer>();
        }
        for(int i=1;i<=m;i++){
            int a=in.nextInt(),b=in.nextInt();
            // graph[a].add(b);graph[b].add(a);
        }
        // boolean[] visited=new boolean[n+1];
        // int change=0;
        // for(int i=1;i<=n;i++){
        //     if(visited[i])continue;
        //     Queue<Integer> q=new LinkedList<Integer>();
        //     Map<Integer,Integer> map=new HashMap<Integer,Integer>();
        //     q.add(i);visited[i]=true;
        //     int max=0;
        //     while(!q.isEmpty()){
        //         int x=q.remove();
        //         change++;
        //         map.put(socks[x],map.getOrDefault(socks[x],0)+1);
        //         max=Math.max(max,map.get(socks[x]));
        //     }
        //     change-=max;
        // }
        System.out.println(1);
    }
}


import java.util.*;

public class proC{
    public static void main(String[] args){
        Scanner in=new Scanner(System.in);
        int n=in.nextInt(),m=in.nextInt(),k=in.nextInt();
        int[] socks=new int[n];
        for(int i=0;i<n;i++)socks[i]=in.nextInt();
        Map<Integer,Integer> map=new HashMap<Integer,Integer>();
        int[][] pair=new int[m][2];
        for(int i=0;i<m;i++){
            pair[i][0]=in.nextInt()-1;
            pair[i][1]=in.nextInt()-1;
            map.put(pair[i][0],map.getOrDefault(pair[i][0],0)+1);
            map.put(pair[i][1],map.getOrDefault(pair[i][1],0)+1);
        }
        int res=0;
        for(int i=0;i<m;i++){
            int a=pair[i][0],b=pair[i][1];
            if(socks[a]!=socks[b]){
                if(map.get(a)>map.get(b)){
                    socks[b]=socks[a];
                }else socks[a]=socks[b];
                res++;
            }
        }
        System.out.println(res);
    }
}


import java.util.*;

public class proC{
    public static void main(String[] args){
        Scanner in=new Scanner(System.in);
        int n=in.nextInt(),m=in.nextInt(),k=in.nextInt();
        int[] socks=new int[n];
        for(int i=0;i<n;i++)socks[i]=in.nextInt();
        Map<Integer,Integer> map=new HashMap<Integer,Integer>();
        int[][] pair=new int[m][2];
        for(int i=0;i<m;i++){
            pair[i][0]=in.nextInt()-1;
            pair[i][1]=in.nextInt()-1;
            map.put(pair[i][0],map.getOrDefault(pair[i][0],0)+1);
            map.put(pair[i][1],map.getOrDefault(pair[i][1],0)+1);
        }
        int res=0;
        for(int i=0;i<m;i++){
            int a=pair[i][0],b=pair[i][1];
            if(socks[a]!=socks[b]){
                if(map.get(a)>map.get(b)){
                    socks[b]=socks[a];
                    map.put(a,map.get(a)+map.get(b));
                    map.put(b,0);
                }else{
                    socks[a]=socks[b];
                    map.put(b,map.get(b)+map.get(a));
                    map.put(a,0);
                }
                res++;
            }
        }
        System.out.println(res);
    }
}


import java.util.*;

public class proC{
    public staic void main(String[] args){
        Scanner in=new Scanner(System.in);
        int n=in.nextInt(),m=in.nextInt(),k=in.nextInt();
        List<Integer>[] graph=(ArrayList<Integer>[])new ArrayList[n+1];
        int[] socks=new int[n+1];
        for(int i=1;i<=n;i++){
            socks[i]=in.nextInt();
            graph[i]=new ArrayList<Integer>();
        }
        for(int i=1;i<=m;i++){
            int a=in.nextInt(),b=in.nextInt();
            graph[a].add(b);graph[b].add(a);
        }
        boolean[] visited=new boolean[n+1];
        int change=0;
        for(int i=1;i<=n;i++){
            if(visited[i])continue;
            Queue<Integer> q=new LinkedList<Integer>();
            Map<Integer,Integer> map=new HashMap<Integer,Integer>();
            q.add(i);visited[i]=true;
            int max=0;
            while(!q.isEmpty()){
                int x=q.remove();
                change++;
                map.put(socks[x],map.getOrDefault(socks[x],0)+1);
                max=Math.max(max,map.get(socks[x]));
            }
            change-=max;
        }
        System.out.println(change);
    }
}


import java.util.*;

public class proC{
    public staic void main(String[] args){
        Scanner in=new Scanner(System.in);
        int n=in.nextInt(),m=in.nextInt(),k=in.nextInt();
        // ArrayList<Integer>[] graph=new ArrayList[n+1];
        // int[] socks=new int[n+1];
        // for(int i=1;i<=n;i++){
        //     socks[i]=in.nextInt();
        //     graph[i]=new ArrayList<Integer>();
        // }
        // for(int i=1;i<=m;i++){
        //     int a=in.nextInt(),b=in.nextInt();
        //     graph[a].add(b);graph[b].add(a);
        // }
        // boolean[] visited=new boolean[n+1];
        // int change=0;
        // for(int i=1;i<=n;i++){
        //     if(visited[i])continue;
        //     Queue<Integer> q=new LinkedList<Integer>();
        //     Map<Integer,Integer> map=new HashMap<Integer,Integer>();
        //     q.add(i);visited[i]=true;
        //     int max=0;
        //     while(!q.isEmpty()){
        //         int x=q.remove();
        //         change++;
        //         map.put(socks[x],map.getOrDefault(socks[x],0)+1);
        //         max=Math.max(max,map.get(socks[x]));
        //     }
        //     change-=max;
        // }
        // System.out.println(change);
    }
}


import java.util.*;

public class proC{
    public static void main(String[] args){
        Scanner in=new Scanner(System.in);
        int n=in.nextInt(),m=in.nextInt(),k=in.nextInt();
        ArrayList<Integer>[] graph=new ArrayList[n+1];
        int[] socks=new int[n+1];
        for(int i=1;i<=n;i++){
            socks[i]=in.nextInt();
            graph[i]=new ArrayList<Integer>();
        }
        for(int i=1;i<=m;i++){
            int a=in.nextInt(),b=in.nextInt();
            graph[a].add(b);graph[b].add(a);
        }
        boolean[] visited=new boolean[n+1];
        int change=0;
        for(int i=1;i<=n;i++){
            if(visited[i])continue;
            Queue<Integer> q=new LinkedList<Integer>();
            Map<Integer,Integer> map=new HashMap<Integer,Integer>();
            q.add(i);visited[i]=true;
            int max=0;
            while(!q.isEmpty()){
                int x=q.remove();
                change++;
                map.put(socks[x],map.getOrDefault(socks[x],0)+1);
                max=Math.max(max,map.get(socks[x]));
                for(int next:graph[x]){
                    if(visited[next])continue;
                    q.add(next);
                }
            }
            change-=max;
        }
        System.out.println(change);
    }
}


import java.util.*;

public class proC{
    public static void main(String[] args){
        Scanner in=new Scanner(System.in);
        int n=in.nextInt(),m=in.nextInt(),k=in.nextInt();
        // ArrayList<Integer>[] graph=new ArrayList[n+1];
        int[] socks=new int[n+1];
        for(int i=1;i<=n;i++){
            socks[i]=in.nextInt();
            // graph[i]=new ArrayList<Integer>();
        }
        for(int i=1;i<=m;i++){
            int a=in.nextInt(),b=in.nextInt();
            // graph[a].add(b);graph[b].add(a);
        }
        // boolean[] visited=new boolean[n+1];
        // int change=0;
        // for(int i=1;i<=n;i++){
        //     if(visited[i])continue;
        //     Queue<Integer> q=new LinkedList<Integer>();
        //     Map<Integer,Integer> map=new HashMap<Integer,Integer>();
        //     q.add(i);visited[i]=true;
        //     int max=0;
        //     while(!q.isEmpty()){
        //         int x=q.remove();
        //         change++;
        //         map.put(socks[x],map.getOrDefault(socks[x],0)+1);
        //         max=Math.max(max,map.get(socks[x]));
        //     }
        //     change-=max;
        // }
        System.out.println(1);
    }
}


import java.util.*;

public class proC{
    public staic void main(String[] args){
        Scanner in=new Scanner(System.in);
        int n=in.nextInt(),m=in.nextInt(),k=in.nextInt();
        // ArrayList<Integer>[] graph=new ArrayList[n+1];
        // int[] socks=new int[n+1];
        // for(int i=1;i<=n;i++){
        //     socks[i]=in.nextInt();
        //     graph[i]=new ArrayList<Integer>();
        // }
        // for(int i=1;i<=m;i++){
        //     int a=in.nextInt(),b=in.nextInt();
        //     graph[a].add(b);graph[b].add(a);
        // }
        // boolean[] visited=new boolean[n+1];
        // int change=0;
        // for(int i=1;i<=n;i++){
        //     if(visited[i])continue;
        //     Queue<Integer> q=new LinkedList<Integer>();
        //     Map<Integer,Integer> map=new HashMap<Integer,Integer>();
        //     q.add(i);visited[i]=true;
        //     int max=0;
        //     while(!q.isEmpty()){
        //         int x=q.remove();
        //         change++;
        //         map.put(socks[x],map.getOrDefault(socks[x],0)+1);
        //         max=Math.max(max,map.get(socks[x]));
        //     }
        //     change-=max;
        // }
        System.out.println(1);
    }
}


import java.util.*;

public class proC{
    public static void main(String[] args){
        Scanner in=new Scanner(System.in);
        int n=in.nextInt(),m=in.nextInt(),k=in.nextInt();
        ArrayList<Integer>[] graph=new ArrayList[n+1];
        int[] socks=new int[n+1];
        for(int i=1;i<=n;i++){
            socks[i]=in.nextInt();
            graph[i]=new ArrayList<Integer>();
        }
        for(int i=1;i<=m;i++){
            int a=in.nextInt(),b=in.nextInt();
            graph[a].add(b);graph[b].add(a);
        }
        boolean[] visited=new boolean[n+1];
        int change=0;
        for(int i=1;i<=n;i++){
            if(visited[i])continue;
            Queue<Integer> q=new LinkedList<Integer>();
            Map<Integer,Integer> map=new HashMap<Integer,Integer>();
            q.add(i);visited[i]=true;
            int max=0;
            while(!q.isEmpty()){
                int x=q.remove();
                change++;
                map.put(socks[x],map.getOrDefault(socks[x],0)+1);
                max=Math.max(max,map.get(socks[x]));
            }
            change-=max;
        }
        System.out.println(change);
    }
}


import java.util.*;

public class proC{
    public static void main(String[] args){
        Scanner in=new Scanner(System.in);
        int n=in.nextInt(),m=in.nextInt(),k=in.nextInt();
        int[] socks=new int[n];
        for(int i=0;i<n;i++)socks[i]=in.nextInt();
        Map<Integer,Integer> map=new HashMap<Integer,Integer>();
        Map<Integer,Integer> map2=new HashMap<Integer,Integer>();
        int[][] pair=new int[m][2];
        for(int i=0;i<m;i++){
            pair[i][0]=in.nextInt()-1;
            pair[i][1]=in.nextInt()-1;
            map.put(pair[i][0],map.getOrDefault(pair[i][0],0)+1);
            map.put(pair[i][1],map.getOrDefault(pair[i][1],0)+1);
            map2.put(socks[pair[i][0]],map.getOrDefault(socks[pair[i][0]],0)+1);
            map2.put(socks[pair[i][1]],map.getOrDefault(socks[pair[i][1]],0)+1);
        }
        int res=0;
        for(int i=0;i<m;i++){
            int a=pair[i][0],b=pair[i][1];
            if(socks[a]!=socks[b]){
                if(map2.get(socks[a])>map2.get(socks[b])){
                    socks[b]=socks[a];
                    map.put(a,map.get(a)+map.get(b));
                    map.put(b,0);
                }else{
                    socks[a]=socks[b];
                    map.put(b,map.get(b)+map.get(a));
                    map.put(a,0);
                }
                res++;
            }
        }
        System.out.println(res);
    }
}


#include <bits/stdc++.h>
using namespace std;
string ans[1000002];
int cr[1000002];
int main() {
    for(int i=0;i<1000002;i++){
    	ans[i]=to_string(0);
    }
    int v;
    cin>>v;
    int t[9];
    for(int i=0;i<9;i++){
        cin>>t[i];
        ans[t[i]]=to_string(i+1);
        cr[t[i]]=i+1;
    }
    int i=1;
    while(i<=v){
        for(int j=0;j<9;j++){
            if(i+t[j]<=v&&ans[i]!="0"){
                string curr=ans[i]+to_string(j+1);
                sort(curr.begin(),curr.end());
                string s=ans[i+t[j]];
                sort(s.begin(),s.end());
                if(curr.length()>s.length()){
                    ans[i+t[j]]=curr;
                    cr[i+t[j]]=cr[i]+cr[j+1];
                }else if(curr.length()==s.length()&&cr[i+t[j]]<cr[i]+cr[j+1]){
                    ans[i+t[j]]=curr;
                    cr[i+t[j]]=cr[i]+cr[j+1];
                }
            }
        }
        i++;
    }
    if(ans[v]!="0"){
        cout<<ans[v];
    }else{
        cout<<-1;
    }
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
string ans[1000002];
int main() {
    for(int i=0;i<1000002;i++){
    	ans[i]=to_string(0);
    }
    int v;
    cin>>v;
    int t[9];
    for(int i=0;i<9;i++){
        cin>>t[i];
        ans[t[i]]=to_string(i+1);
    }
    int i=1;
    while(i<=v){
        for(int j=0;j<9;j++){
            if(i+t[j]<=v){
                string curr=ans[i]+to_string(j+1);
                sort(curr.begin(),curr.end());
                string s=ans[i+t[j]];
                sort(s.begin(),s.end());
                if(s.length()<curr.length()){
                    ans[i+t[j]]=curr;
                }else if(s.length()==curr.length()){
                    if(s[0]-'0'<curr[0]-'0'){
                       ans[i+t[j]]=curr;
                    }else if(s[0]-'0'<curr[0]-'0'){
                        for(int l=0;l<curr.length();l++){
                            if(s[l]-'0'<curr[l]-'0'){
                                ans[i+t[j]]=curr;
                            }
                        }
                    }
                }
            }
        }
        i++;
    }
    if(ans[v]!="0"){
        cout<<ans[v];
    }else{
        cout<<-1;
    }
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
string ans[1000006];
int main() {
    for(int i=0;i<1000006;i++){
    	ans[i]=to_string(-1);
    }
    int v;
    cin>>v;
    int t[9];
    for(int i=0;i<9;i++){
        cin>>t[i];
        ans[t[i]]=to_string(i+1);
    }
    int i=1;
    while(i<=v){
        for(int j=0;j<9;j++){
            string curr=ans[i]+to_string(j+1);
            sort(curr.begin(),curr.end());
            string s=ans[i+t[j]];
            sort(ans[i+t[j]].begin(),ans[i+t[j]].end());
            if(i+t[j]<=v&&stoi(ans[i+t[j]])<stoi(curr)){
                ans[i+t[j]]=curr;
            }
        }
        i++;
    }
    if(ans[v]!="-1"){
        cout<<ans[v];
    }else{
        cout<<-1;
    }
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
string ans[1000002];
int main() {
    for(int i=0;i<1000002;i++){
    	ans[i]=to_string(0);
    }
    int v;
    cin>>v;
    int t[9];
    for(int i=0;i<9;i++){
        cin>>t[i];
        ans[t[i]]=to_string(i+1);
    }
    int i=1;
    while(i<=v){
        for(int j=0;j<9;j++){
            if(i+t[j]<=v){
                string curr=ans[i]+to_string(j+1);
                sort(curr.begin(),curr.end());
                string s=ans[i+t[j]];
                sort(s.begin(),s.end());
                if(s.length()<curr.length()){
                    ans[i+t[j]]=curr;
                }else if(s.length()==curr.length()){
                    if(s[0]-'0'<curr[0]-'0'){
                       ans[i+t[j]]=curr;
                    }else if(s[0]-'0'<curr[0]-'0'){
                        for(int l=0;l<curr.length();l++){
                            if(s[l]-'0'<curr[l]-'0'){
                                ans[i+t[j]]=curr;
                                break;
                            }
                        }
                    }
                }
            }
        }
        i++;
    }
    if(ans[v]!="0"){
        cout<<ans[v];
    }else{
        cout<<-1;
    }
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int v, x = 1, t[12];
string ans;

int main () {
    scanf("%d", &v);
    for (int i = 1; i <= 9; i++) {
        scanf("%d", &t[i]);
        if (t[i] <= t[x]) x = i;
    }
    while (t[x] <= v) {
        ans += x + '0';
        v -= t[x];
    }
    for (char &c : ans) {
        for (int i = 9; i >= x; i--) {
            if (t[i] - t[x] <= v) {
                v -= t[i] - t[x];
                c = i + '0';
                break;
            }
        }
    }
    puts (ans.empty() ? "-1" : ans.c_str());
}


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

int main() {
    int v,m=0,res=0;
    string s;
    cin>>v;
    int t[9];
    for(int i=0;i<9;i++){
        cin>>t[i];
        if(v/t[i] >= m){
            m=v/t[i];
            s=(to_string(i+1));
            res=v-(m*t[i]);
        }
    }
    int curr=0;
    string ans="";
    for(int i=0;i<m;i++){
    	ans+=s;
    }
    if(res>0){
        string st;
        for(int i=0;i<9;i++){
            if(res/t[i] > 0&&res%t[i]==0&&res/t[i]>curr){
                curr=res/t[i];
                st=(to_string(i+1));
            }
        }
        for(int i=0;i<curr;i++){
    	    ans+=st;
        }
    }
    sort(ans.begin(),ans.end());
    if(ans==""){
    	cout<<-1;
    }else{
    	cout<<ans;
    }
	return 0;
}


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

#define ll long long
#define f1(n)  for(ll i=0;i<(n);++i)
#define f2(n)  for(ll j=0;j<(n);++j)
#define _fast_   ios_base::sync_with_stdio(false),cin.tie(NULL);
#define pb  push_back
#define f_1(a,b) for(ll i=a;i<=b;i++)
#define f_2(a,b) for(ll j=a;j>=b;j--)
#define v(name) vector<ll> name
#define sz(a)  a.size()
const int MAX=5e5+10,mod=1e9+9,base=41,INF=1e9+10,sq=502;

int main()
{

    _fast_
    ll v;
    cin>>v;
    vector<pair<int,int>>pp;
   ll min=INT_MAX;
    f1(9)
   {
   	ll a;
    cin>>a;
    if(a<min)
    	min=a;
    pp.pb({a,i+1});
   }
   cout<<min<<endl;
   //sort(pp.begin(),pp.end());
   f1(9)
    cout<<pp[i].first<<" "<<pp[i].second<<endl;
   if(v<min)
   {
   	cout<<-1<<endl;
   }
   else
   	{
      ll val =min;
      ll ans=0,ind=0;
      f1(9)
      {
        if(val==pp[i].first)
        {
        	ind=i;
        }
     }
      if(v%2==0 or val==1)
      {
      	f1(v/val)
      	cout<<pp[ind].second;
      	cout<<endl;
      }
      else
      {
      	ll m=v;
       while(v>val)
      {
      	ll p=0;
      	ll req = val + (v%val);
      	f_1(0,8)
      	{
      		if(pp[i].first<=req)
      		{
               p=i;
       		}
        }
       //	cout<<pp[p].second;
      	v -=pp[p].first;
      	cout<<pp[p].second;
      }
      	f1((v/val))
      	cout<<pp[ind].second;
      	cout<<endl;
      }
   	}
	return 0;
}


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

#define ll long long
#define f1(n)  for(ll i=0;i<(n);++i)
#define f2(n)  for(ll j=0;j<(n);++j)
#define _fast_   ios_base::sync_with_stdio(false),cin.tie(NULL);
#define pb  push_back
#define f_1(a,b) for(ll i=a;i<=b;i++)
#define f_2(a,b) for(ll j=a;j>=b;j--)
#define v(name) vector<ll> name
#define sz(a)  a.size()
const int MAX=5e5+10,mod=1e9+9,base=41,INF=1e9+10,sq=502;

int main()
{

    _fast_
    ll v;
    cin>>v;
    vector<pair<int,int>>pp;
    f1(9)
   {
   	ll a;
    cin>>a;
    pp.pb({a,i+1});
   }
   sort(pp.begin(),pp.end());
   /*f1(9)
    cout<<pp[i].first<<" "<<pp[i].second<<endl;
  */ if(v<pp[0].first)
   {
   	cout<<-1<<endl;
   }
   else
   	{
      ll val =pp[0].first;
      ll ans=0,ind=0;
      f1(9)
      {
        if(val!=pp[i].first)
        {
        	ind=i;
        	break;
        }
      }
      if(v%2==0 or val==1)
      {
      	f1(v/val)
      	cout<<pp[ind-1].second;
      	cout<<endl;
      }
      else
      {
      	ll p=0;
      	ll req = val + (v%val);
      	f_1(ind,8)
      	{
      		if(pp[i].first<=req)
      		{
               p=i;
      		}
      	}
      	cout<<pp[p].second;
      	f1((v/val)-1)
      	cout<<pp[ind-1].second;
      	cout<<endl;
      }
   	}
	return 0;
}


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

#define ll long long
#define f1(n)  for(ll i=0;i<(n);++i)
#define f2(n)  for(ll j=0;j<(n);++j)
#define _fast_   ios_base::sync_with_stdio(false),cin.tie(NULL);
#define pb  push_back
#define f_1(a,b) for(ll i=a;i<=b;i++)
#define f_2(a,b) for(ll j=a;j>=b;j--)
#define v(name) vector<ll> name
#define sz(a)  a.size()
const int MAX=5e5+10,mod=1e9+9,base=41,INF=1e9+10,sq=502;

int main()
{

    _fast_
    ll v;
    cin>>v;
    vector<pair<int,int>>pp;
    f1(9)
   {
   	ll a;
    cin>>a;
    pp.pb({a,i+1});
   }
   sort(pp.begin(),pp.end());
   /*f1(9)
    cout<<pp[i].first<<" "<<pp[i].second<<endl;
  */ if(v<pp[0].first)
   {
   	cout<<-1<<endl;
   }
   else
   	{
      ll val =pp[0].first;
      ll ans=0,ind=0;
      f1(9)
      {
        if(val!=pp[i].first)
        {
        	ind=i;
        	break;
        }

      }
      if(v%2==0 or val==1)
      {
      	if(ind==0)
      		ind=9;
      	f1(v/val)
      	cout<<pp[ind-1].second;
      	cout<<endl;
      }
      else
      {
      	ll p=0;
      	ll req = val + (v%val);
      	f_1(ind,8)
      	{
      		if(pp[i].first<=req)
      		{
               p=i;
      		}
      	}
      	cout<<pp[p].second;
      	f1((v/val)-1)
      	cout<<pp[ind-1].second;
      	cout<<endl;
      }
   	}
	return 0;
}


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

#define ll long long
#define f1(n)  for(ll i=0;i<(n);++i)
#define f2(n)  for(ll j=0;j<(n);++j)
#define _fast_   ios_base::sync_with_stdio(false),cin.tie(NULL);
#define pb  push_back
#define f_1(a,b) for(ll i=a;i<=b;i++)
#define f_2(a,b) for(ll j=a;j>=b;j--)
#define v(name) vector<ll> name
#define sz(a)  a.size()
const int MAX=5e5+10,mod=1e9+9,base=41,INF=1e9+10,sq=502;

int main()
{

    _fast_
    ll v;
    cin>>v;
    vector<pair<int,int>>pp;
   ll min=INT_MAX;
    f1(9)
   {
   	ll a;
    cin>>a;
    if(a<min)
    	min=a;
    pp.pb({a,i+1});
   }
  /* cout<<min<<endl;
   //sort(pp.begin(),pp.end());
   f1(9)
    cout<<pp[i].first<<" "<<pp[i].second<<endl;
   */if(v<min)
   {
   	cout<<-1<<endl;
   }
   else
   	{
      ll val =min;
      ll ans=0,ind=0;
      f1(9)
      {
        if(val==pp[i].first)
        {
        	ind=i;
        }
     }
      if(v%2==0 or val==1)
      {
      	f1(v/val)
      	cout<<pp[ind].second;
      	cout<<endl;
      }
      else
      {
      	ll m=v;
       while(v>val)
      {
      	ll p=0;
      	ll req = val + (v%val);
      	f_1(0,8)
      	{
      		if(pp[i].first<=req)
      		{
               p=i;
       		}
        }
       //	cout<<pp[p].second;
      	v -=pp[p].first;
      	cout<<pp[p].second;
      }
      	f1((v/val))
      	cout<<pp[ind].second;
      	cout<<endl;
      }
   	}
	return 0;
}