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

public class Reinier {
    public static void main(String[] args) throws IOException {
        try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
            new Reinier().run(reader);
        }
    }
	
	public int[][] A;
	public int[][][] D;
	public int m, n;

    public void run(BufferedReader reader) throws IOException {
		Scanner sc = new Scanner(reader);
		long n = sc.nextLong();
		int k = sc.nextInt();
		long res = 0;
		long[] A = new long[k];
		long s = 0;
		for (long i = 0; i < n; i++) {
			long w = sc.nextLong();
			s += w;
			w %= k;
			if (w == 0) {
				res--;
				continue;
			}
			if (A[(int) (k-w)] > 0) {
				A[(int) (k-w)]--;
				res--;
			} else {
				A[(int) w]++;
			}
		}
		res += s/k;
		long[] B = new long[4];
		int[] C = new int[4];
		int j = 0;
		for (int i = 1; i < k; i++) {
			if (A[i] > 0) {
				B[j] = i; C[j] = (int) A[i];
				j++;
			}
		}
		long[][][][] T = new long[C[0]+1][C[1]+1][C[2]+1][C[3]+1];
		for (int a = 0; a <= C[0]; a++) {
			for (int b = 0; b <= C[1]; b++) {
				for (int c = 0; c <= C[2]; c++) {
					for (int d = 0; d <= C[3]; d++) {
						T[a][b][c][d] = -1;
						if (a > 0) {
							T[a][b][c][d] = Math.max(T[a][b][c][d], T[a-1][b][c][d]);
						}
						if (b > 0) {
							T[a][b][c][d] = Math.max(T[a][b][c][d], T[a][b-1][c][d]);
						}
						if (c > 0) {
							T[a][b][c][d] = Math.max(T[a][b][c][d], T[a][b][c-1][d]);
						}
						if (d > 0) {
							T[a][b][c][d] = Math.max(T[a][b][c][d], T[a][b][c][d-1]);
						}
						if ((a*B[0] + b*B[1] + c*B[2] + d*B[3])%k == 0) {
							T[a][b][c][d]++;
						}
					}
				}
			}
		}
		res -= T[C[0]][C[1]][C[2]][C[3]];
		System.out.println(res);
    }
}
