#include <bits/stdc++.h>
using namespace std;
inline void INP() {}
const long long inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3f;
long long n, m, k, q;
string s;
vector<long long> adj[(long long)1e6 + 5];
long long dp[(long long)1e6 + 5][3][3], fr[(long long)1e6 + 5],
    a[(long long)1e6 + 5];
long long maxPlay(long long i, long long x, long long y) {
  if (i > m) return 0;
  if (fr[i] < x) return -INF;
  long long& ans = dp[i][x][y];
  if (~ans) return ans;
  long long play = maxPlay(i + 1, y, 0) + (fr[i] - x) / 3;
  if ((i + 2) <= m and (fr[i] - x - 1) >= 0) {
    long long aa = maxPlay(i + 1, y + 1, 1) + ((fr[i] - x - 1) / 3 + 1);
    play = max(play, aa);
  }
  if ((i + 2) <= m and (fr[i] - x - 2) >= 0) {
    long long aa = maxPlay(i + 1, y + 2, 2) + ((fr[i] - x - 2) / 3 + 2);
    play = max(play, aa);
  }
  return ans = play;
}
void go() {
  cin >> n >> m;
  for (long long i = 0; i < n; i++) {
    long long x;
    cin >> x;
    fr[x]++;
  }
  memset(dp, -1, sizeof dp);
  long long ans = maxPlay(1, 0, 0);
  cout << ans << '\n';
}
int32_t main() {
  INP();
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long t = 1;
  while (t--) go();
}
