MAX_X = 10 ** 5 + 100



def main():

    N, M = [int(i) for i in input().split()]

    X = [0] * (MAX_X + 1)

    for i in map(int, input().split()):

        X[i] += 1

    Y = [sum(X[i::M]) for i in range(min(M, MAX_X))]

    # Mの倍数    

    ans = Y[0] // 2

    Y[0] = 0

    # M%2==0のM/2

    if M % 2 == 0:

        ans += Y[M//2] // 2

        Y[M//2] = 0    

    for i in range(1, M//2+1):

        j = M - i

        tmp = min(Y[i], Y[j])

        ans += tmp

        Y[i] -= tmp

        Y[j] -= tmp

    try:

        for i, n in enumerate(X):

            j = i % M

            if Y[j] < 2 or n < 2:

                continue

            tmp = min(Y[j]-Y[j]%2, n-n%2)

            ans += tmp // 2

            Y[j] -= tmp

    except IndexError:

        print((-1))

    print(ans)



if __name__ == "__main__":

    main()

MAX_X = 10 ** 5 + 100



def main():

    N, M = [int(i) for i in input().split()]

    X = [0] * (MAX_X + 1)

    for i in map(int, input().split()):

        X[i] += 1

    Y = [sum(X[i::M]) for i in range(min(M, MAX_X))]

    # Mの倍数    

    ans = Y[0] // 2

    Y[0] = 0

    # M%2==0のM/2

    try:

        if M % 2 == 0:

            ans += Y[M//2] // 2

            Y[M//2] = 0    

        for i in range(1, M//2+1):

            j = M - i

            tmp = min(Y[i], Y[j])

            ans += tmp

            Y[i] -= tmp

            Y[j] -= tmp

    except IndexError:

        print((-1))

    for i, n in enumerate(X):

        j = i % M

        if Y[j] < 2 or n < 2:

            continue

        tmp = min(Y[j]-Y[j]%2, n-n%2)

        ans += tmp // 2

        Y[j] -= tmp

    print(ans)



if __name__ == "__main__":

    main()

MAX_X = 10**5 + 100


def main():
    N, M = [int(i) for i in input().split()]
    X = [0] * (MAX_X + 1)
    for i in map(int, input().split()):
        X[i] += 1
    Y = [sum(X[i::M]) for i in range(min(M, MAX_X))]
    # Mの倍数
    ans = Y[0] // 2
    Y[0] = 0
    # M%2==0のM/2
    if M % 2 == 0:
        ans += Y[M // 2] // 2
        Y[M // 2] = 0
    for i in range(1, M // 2 + 1):
        j = M - i
        tmp = min(Y[i], Y[j])
        ans += tmp
        Y[i] -= tmp
        Y[j] -= tmp
    try:
        for i, n in enumerate(X):
            j = i % M
            if Y[j] < 2 or n < 2:
                continue
            tmp = min(Y[j] - Y[j] % 2, n - n % 2)
            ans += tmp // 2
            Y[j] -= tmp
    except IndexError:
        print((-1))
    print(ans)


if __name__ == "__main__":
    main()

MAX_X = 10**5 + 100


def main():
    N, M = [int(i) for i in input().split()]
    X = [0] * (MAX_X + 1)
    for i in map(int, input().split()):
        X[i] += 1
    Y = [sum(X[i::M]) for i in range(min(M, MAX_X))]
    # Mの倍数
    ans = Y[0] // 2
    Y[0] = 0
    # M%2==0のM/2
    try:
        if M % 2 == 0:
            ans += Y[M // 2] // 2
            Y[M // 2] = 0
        for i in range(1, M // 2 + 1):
            j = M - i
            tmp = min(Y[i], Y[j])
            ans += tmp
            Y[i] -= tmp
            Y[j] -= tmp
    except IndexError:
        print((-1))
    for i, n in enumerate(X):
        j = i % M
        if Y[j] < 2 or n < 2:
            continue
        tmp = min(Y[j] - Y[j] % 2, n - n % 2)
        ans += tmp // 2
        Y[j] -= tmp
    print(ans)


if __name__ == "__main__":
    main()

-    if M % 2 == 0: -        ans += Y[M // 2] // 2 -        Y[M // 2] = 0 -    for i in range(1, M // 2 + 1): -        j = M - i -        tmp = min(Y[i], Y[j]) -        ans += tmp -        Y[i] -= tmp -        Y[j] -= tmp -        for i, n in enumerate(X): -            j = i % M -            if Y[j] < 2 or n < 2: -                continue -            tmp = min(Y[j] - Y[j] % 2, n - n % 2) -            ans += tmp // 2 +        if M % 2 == 0: +            ans += Y[M // 2] // 2 +            Y[M // 2] = 0 +        for i in range(1, M // 2 + 1): +            j = M - i +            tmp = min(Y[i], Y[j]) +            ans += tmp +            Y[i] -= tmp +    for i, n in enumerate(X): +        j = i % M +        if Y[j] < 2 or n < 2: +            continue +        tmp = min(Y[j] - Y[j] % 2, n - n % 2) +        ans += tmp // 2 +        Y[j] -= tmp