#include <bits/stdc++.h>
using namespace std;
int n, m;
const int N = 2e6 + 100;
int a[N], dp[N][3][3];
int ans(int i, int r1, int r2) {
  if (i == m + 1) return 0;
  if (dp[i][r1][r2] != -1) return dp[i][r1][r2];
  int cur1 = a[i] - r1, cur2 = a[i + 1] - r2, cur3 = a[i + 2];
  int mi = min(cur1, min(cur2, cur3));
  if (mi > 3) mi = 2;
  int w1 = (cur1) / 3 + ans(i + 1, r2, 0);
  if (mi) w1 = max(w1, 1 + (cur1 - 1) / 3 + ans(i + 1, r2 + 1, 1));
  if (mi > 1) w1 = max(w1, 2 + (cur1 - 2) / 3 + ans(i + 1, r2 + 2, 2));
  dp[i][r1][r2] = w1;
  return w1;
}
int main() {
  memset(dp, -1, sizeof dp);
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) {
    int u;
    scanf("%d", &u);
    a[u]++;
  }
  cout << ans(0, 0, 0) << endl;
}
