#include <bits/stdc++.h>
// #include "/usr/local/include/cxx_pretty_print/cxx_pretty_print.hpp"

using namespace std;
/* type aliases */
using i32 = int32_t; using ui32 = uint32_t; using i64 = int64_t; using ui64 = uint64_t; using i128 = __int128;
using f32 = float;   using f64  = double;   using f80 = long double;
using PII = pair<i32, i32>; using PLL = pair<i64, i64>; using PFF = pair<f32, f32>; using PDD = pair<f64, f64>;
using VB  = vector<bool>;   using VS  = vector<string>;
using VI  = vector<i32>;    using VL  = vector<i64>;    using VF  = vector<f32>;    using VD  = vector<f64>;
using VVI = vector<VI>;     using VVL = vector<VL>;     using VVF = vector<VF>;     using VVD = vector<VD>;
using VPI = vector<PII>;    using VPL = vector<PLL>;    using VPF = vector<PFF>;    using VPD = vector<PDD>;
/* constants */
constexpr i64 mod = 1000000007;                                // 10^9+7
constexpr i64 inf = 9000000000000000000;                       // 9*10^18
/* macros */
#define MAX(c)        *max_element(ALL(c))
#define MIN(c)        *min_element(ALL(c))
#define SIZE(c)       (i64)((c).size())                        // unsined int (size_t) -> int64_t
#define ALL(c)        (c).begin(), (c).end()
#define RALL(c)       (c).rbegin(), (c).rend()
#define REP(i, n)     for (i64 i=0; i<(i64)(n); ++i)           // 0 to n-1
#define REPD(i, n)    for (i64 i=(i64)(n)-1; i>=0; --i)        // n-1 to 0
/* debug */
#define debug(x)      cerr << #x << ": " << (x) << '\n'
#define debugvec(v)   for (size_t _ = 0; _ < (v).size(); ++_) {cerr << #v << '[' << _ << "]: " << (v)[_] << '\n';}
/* useful output */
auto print = [](auto x) {cout << (x) << '\n';};
template <class T> void printvec(T v, string sep=" ", string end="\n") {REP(i, SIZE(v)-1) cout << v[i] << sep; cout << v[SIZE(v)-1] << end;}
/* useful input */
VS splitstr(string s, char delim=' ') {VS v; string buf; stringstream ss{s}; while (getline(ss, buf, delim)) v.push_back(buf); return v;}


void greedy_decf(i32 cnt, VI& v) {
    for (auto&& e: v) {
        if (cnt == 0) return;
        if (e % 2 == 1) {
            e--;
            cnt--;
        }
    }
    while (cnt > 0) {
        i32& tail = v.back();
        if (tail <= cnt) {
            v.pop_back();
            cnt -= tail;
        } else {
            tail -= cnt;
            cnt = 0;
        }
    }
}



void Main() {
    i32 n, m;
    cin >> n >> m;
    VI vec(n, 0);
    VI counter(100001, 0);
    REP(i, n) {
        i32 num;
        cin >> num;
        vec.at(i) = num;
        counter.at(num)++;
    }
    VVI modcnt(m, VI{});
    REP(i, 100001) {
        i32 cnt = counter.at(i);
        if (cnt) {
            modcnt.at(i % m).push_back(cnt);
        }
    }

    i32 ans{};
    REP(i, m / 2 + 1) {
        i32 j = (m - i) % m;
        i32 i_group_size = accumulate(ALL(modcnt.at(i)), 0);
        i32 j_group_size = accumulate(ALL(modcnt.at(j)), 0);
        // debug(i);
        // debug(j);
        // debugvec(modcnt.at(i));
        if (i == j) {
            ans += i_group_size / 2;
        } else {
            if (i_group_size < j_group_size) {
                ans += i_group_size;
                greedy_decf(i_group_size, modcnt.at(j));
                for (auto e: modcnt.at(j)) ans += e / 2;
            } else {
                ans += j_group_size;
                greedy_decf(j_group_size, modcnt.at(i));
                for (auto e: modcnt.at(i)) ans += e / 2;
            }
        }
    }
    print(ans);
}


signed main() {
    cin.tie(nullptr);                                         // cin と cout の tie を切り高速化
    cout << fixed << setprecision(15);                        // 浮動小数点数が 1e-006 のように表示されることを防ぐ
    Main();
}

Measured memory_bytes: 9536