#include <bits/stdc++.h>
using namespace std;
ostream& operator<<(ostream& out, pair<int, pair<int, int>>& o) {
  out << o.first << " "
      << "(" << o.second.first << ", " << o.second.second << ")";
  return out;
}
struct Solver {
  int n, m;
  vector<int> sum;
  map<pair<int, pair<int, int>>, int> cache;
  int max;
  Solver() {}
  void input() {
    cin >> n >> m;
    sum.assign(m + 1, 0);
    for (int i = 0; i < n; ++i) {
      int d;
      cin >> d;
      sum[d]++;
    }
  }
  void solve() { max = rec(1); }
  int rec(int i) {
    if (i + 2 > m) {
      int cur = 0;
      for (int j = 0; j < 2 && i + j <= m; ++j) cur += sum[i + j] / 3;
      return cur;
    }
    pair<int, pair<int, int>> is(i, {sum[i], sum[i + 1]});
    if (cache.find(is) != cache.end()) return cache[is];
    int& res = cache[is];
    res = 0;
    int min = *min_element(sum.begin() + i, sum.begin() + i + 3);
    min = std::min(min, 2);
    for (int j = 0; j <= min; ++j) {
      for (int k = 0; k < 3; ++k) sum[i + k] -= j;
      int cur = sum[i] / 3 + j + rec(i + 1);
      res = std::max(res, cur);
      for (int k = 0; k < 3; ++k) sum[i + k] += j;
    }
    return res;
  }
  void output(int testnumber = 0) { cout << max << endl; }
};
int main() {
  cin.sync_with_stdio(false);
  cin.tie(nullptr);
  Solver sol;
  sol.input();
  sol.solve();
  sol.output();
  return 0;
}
