#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pci = pair<char, int>;
using vi = vector<int>;
using vll = vector<ll>;
using vpii = vector<pii>;
using vpll = vector<pll>;
const ll infll = 1e18 + 3;
const int maxn = 1e6 + 77;
const int nmax = 1e6 + 577;
const ll basell = 1e18 + 3;
const int mod = 1e9 + 7;
const ld eps = 1e-7;
const int inf = 1009000999;
const int nv = 100505;
const int baseint = 1000200013;
const ld PI = acos(-1.0);
inline bool EQ(ld a, ld b) { return fabs(a - b) < 1e-9; }
inline bool IF(int a, int b, int c) { return (a >= b && a <= c); }
inline bool IFS(int a, int b, int c) { return (a > b && a < c); }
template <typename T>
inline istream &operator>>(istream &_in, vector<T> &_v) {
  for (auto &_i : _v) {
    _in >> _i;
  }
  return _in;
}
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
char memory[(int)1e8];
char memorypos;
inline void *operator new(size_t n) {
  char *ret = memory + memorypos;
  memorypos += n;
  return (void *)ret;
}
inline void operator delete(void *) {}
int cnt[nmax];
int dp[2][7][7];
int inline solve() {
  ios::sync_with_stdio(NULL), cin.tie(NULL), cout.tie(NULL);
  ;
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    cnt[a]++;
  }
  int ans = 0;
  for (int i = 0; i <= m; ++i) {
    if (cnt[i] > 6) {
      ans += (cnt[i] - 6) / 3;
      cnt[i] = (cnt[i] % 3 + 6);
    }
  }
  memset(dp[0], -1, sizeof(dp[1]));
  dp[0][0][0] = ans;
  for (int i = 0; i < nmax; ++i) {
    memset(dp[1], -1, sizeof(dp[1]));
    for (int j = cnt[i]; j >= 0; --j) {
      int k = (cnt[i] - j) / 3;
      for (int t = 0; t <= 6; ++t) {
        for (int t1 = t; t1 <= j; ++t1) {
          if (dp[0][t][t1] == -1) continue;
          dp[1][t1 - t][j - t] =
              max(dp[1][t1 - t][j - t], dp[0][t][t1] + t + k);
        }
      }
    }
    swap(dp[0], dp[1]);
  }
  for (int i = 0; i <= 6; ++i) {
    for (int j = 0; j <= 6; ++j) {
      ans = max(ans, dp[0][i][j]);
    }
  }
  cout << ans;
  return 0;
}
int32_t main() {
  solve();
  return 0;
}
