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

public class NickyEnMark{

    public static void main(String[] args) throws IOException {
        try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
            int[][][] d = {
                // 0
                {},
                // 1
                {},
                // 2
                {
                    {1, 1}
                },
                // 3
                {
                    {2, 1},
                    {1, 1, 1}
                },
                // 4
                {
                    {3, 1},
                    {2, 2},
                    {2, 1, 1},
                    {1, 1, 1, 1}
                },
                // 5
                {
                    {4, 1},
                    {3, 2},
                    {3, 1, 1},
                    {2, 2, 1},
                    {2, 1, 1, 1},
                    {1, 1, 1, 1, 1}
                },
                // 6
                {
                    {5, 1},
                    {4, 2},
                    {4, 1, 1},
                    {3, 3},
                    {3, 2, 1},
                    {3, 1, 1, 1},
                    {2, 2, 2},
                    {2, 2, 1, 1},
                    {2, 1, 1, 1, 1},
                    {1, 1, 1, 1, 1, 1}
                },
                // 7
                {
                    {6, 1},
                    {5, 2},
                    {5, 1, 1},
                    {4, 3},
                    {4, 2, 1},
                    {4, 1, 1, 1},
                    {3, 3, 1},
                    {3, 2, 2},
                    {3, 2, 1, 1},
                    {3, 1, 1, 1, 1},
                    {2, 2, 2, 1},
                    {2, 2, 1, 1, 1},
                    {2, 1, 1, 1, 1, 1},
                    {1, 1, 1, 1, 1, 1, 1}
                },
                // 8
                {
                    {7, 1},
                    {6, 2},
                    {6, 1, 1},
                    {5, 3},
                    {5, 2, 1},
                    {5, 1, 1, 1},
                    {4, 4},
                    {4, 3, 1},
                    {4, 2, 2},
                    {4, 2, 1, 1},
                    {4, 1, 1, 1, 1},
                    {3, 3, 2},
                    {3, 3, 1, 1},
                    {3, 2, 2, 1},
                    {3, 2, 1, 1, 1},
                    {3, 1, 1, 1, 1, 1},
                    {2, 2, 2, 2},
                    {2, 2, 2, 1, 1},
                    {2, 2, 1, 1, 1, 1},
                    {2, 1, 1, 1, 1, 1, 1},
                    {1, 1, 1, 1, 1, 1, 1, 1}
                }
            };

            String[] line = reader.readLine().split(" ");
            int n = Integer.parseInt(line[0]);
            int k = Integer.parseInt(line[1]);

            int ans = 0;
            int[] counts = new int[k];
            line = reader.readLine().split(" ");
            for (int i = 0; i < n; i++) {
                int w = Integer.parseInt(line[i]);
                ans += (w / k);
                w = w % k;
                if (w != 0) {
                    counts[w]++;
                } else {
                    ans--;
                }
            }

            removeIfFit(counts, d, k);

            while (!done(counts)) {
                int toUse = 0;
                while (toUse < k) {
                    for (int i = k - 1; i > 0; i--) {
                        if (counts[i] > 0) {
                            toUse += i;
                            counts[i]--;
                            break;
                        }
                    }
                }

                if (toUse > k) {
                    counts[toUse - k]++;
                    ans++;
                }

                removeIfFit(counts, d, k);
            }

            System.out.println(ans);
        }
    }

    static void removeIfFit(int[] counts, int[][][] d, int k) {
        for (int i = 0; i < d[k].length; i++) {
            int[] dc = new int[k];
            for (int l = 0; l < d[k][i].length; l++) {
                dc[d[k][i][l]]++;
            }

            boolean possible = true;
            while (possible) {
                for (int l = 1; l < k; l++) {
                    if (dc[l] > counts[l]) {
                        possible = false;
                        break;
                    }
                }

                if (possible) {
                    for (int l = 1; l < k; l++) {
                        counts[l] -= dc[l];
                    }   
                }
            }
        }
    }

    static boolean done(int[] counts) {
        for (int i = 0; i < counts.length; i++) {
            if (counts[i] > 0) {
                return false;
            }
        }

        return true;
    }
}