#include <bits/stdc++.h>
using namespace std;
int h[1000005], n, m, a, ans, t, dp[1000005][3][3];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", &a), h[a]++;
  for (int r = 0; r < 3; r++) dp[1][0][r] = (h[1] - r) / 3;
  for (int i = 1; i < m; i++)
    for (int j = 0; j < 3; j++)
      for (int k = 0; k < 3; k++)
        for (int r = 0; r < 3; r++)
          if (h[i - 1] >= j && h[i] >= j + k && h[i + 1] >= j + k + r &&
              h[i + 2] >= k + r && h[i + 3] >= r)
            dp[i + 1][k][r] = max(dp[i][j][k] + (h[i + 1] - j - k - r) / 3 + j,
                                  dp[i + 1][k][r]);
  printf("%d", dp[m][0][0]);
  return 0;
}
