import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.OutputStream;
import java.util.PriorityQueue;
import java.util.Set;
import java.io.InputStreamReader;
import java.io.FileNotFoundException;
import java.io.File;
import java.util.HashSet;
import java.util.StringTokenizer;
import java.io.Writer;
import java.io.BufferedReader;
import java.util.Comparator;
import java.io.UnsupportedEncodingException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author MaxHeap
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader in = new FastReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        final int MAX = (int) 2e5 + 10;

        public void solve(int testNumber, FastReader in, OutputWriter out) {
            int n = in.nextInt();
            int k = in.nextInt();
            int[] arr = in.nextIntArray(n);
            int[] freq = new int[MAX];
            int dist = 0;
            Set<Integer> set = new HashSet<>();
            for (int i = 0; i < n; i++) {
                if (freq[arr[i]] == 0) {
                    ++dist;
                }
                freq[arr[i]]++;
                set.add(arr[i]);
            }
            PriorityQueue<TaskC.Pair> pq = new PriorityQueue<>(Comparator.comparing(e -> e.s));
            for (Integer element : set) {
                pq.add(new TaskC.Pair(element, freq[element]));
            }
            int ans = 0;
            if (dist <= k) {
                out.println(0);
            } else {
                while (dist > k) {
                    TaskC.Pair cur = pq.poll();
                    dist--;
                    ans += cur.s;
                }
                out.println(ans);
            }
        }

        static class Pair {
            int f;
            int s;

            public Pair(int f, int s) {
                this.f = f;
                this.s = s;
            }

        }

    }

    static class FastReader {
        BufferedReader reader;
        StringTokenizer st;

        public FastReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
            st = null;
        }

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

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public int[] nextIntArray(int n) {
            int[] arr = new int[n];
            int i = 0;
            while (i < n) {
                arr[i++] = nextInt();
            }
            return arr;
        }

    }

    static class OutputWriter extends PrintWriter {
        public OutputWriter(OutputStream os, boolean autoFlush) {
            super(os, autoFlush);
        }

        public OutputWriter(Writer out) {
            super(out);
        }

        public OutputWriter(Writer out, boolean autoFlush) {
            super(out, autoFlush);
        }

        public OutputWriter(String fileName) throws FileNotFoundException {
            super(fileName);
        }

        public OutputWriter(String fileName, String csn) throws FileNotFoundException, UnsupportedEncodingException {
            super(fileName, csn);
        }

        public OutputWriter(File file) throws FileNotFoundException {
            super(file);
        }

        public OutputWriter(File file, String csn) throws FileNotFoundException, UnsupportedEncodingException {
            super(file, csn);
        }

        public OutputWriter(OutputStream out) {
            super(out);
        }


        public void flush() {
            super.flush();
        }


        public void close() {
            super.close();
        }

    }
}



Measured memory_bytes: 54828