#include <bits/stdc++.h>
using namespace std;
const int M = 1e6 + 7;
const long long q = 7057594037927903;
const long long prime = 2137;
int n, m, dp[M][3][3][3], wys[M], a, pom, wynik;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a);
    wys[a]++;
  }
  for (int i = 1; i <= m; i++) {
    pom = min(min(wys[i], wys[i + 1]), wys[i + 2]);
    for (int j = 0; j <= min(pom, 2); j++)
      for (int k = 0; k <= 2; k++)
        for (int z = 0; z <= 2; z++)
          for (int d = 0; d <= 2; d++)
            if (wys[i] - j - k - z >= 0 && wys[i + 1] >= j + k)
              dp[i][j][k][z] =
                  max(dp[i][j][k][z],
                      dp[i - 1][k][z][d] + j + (wys[i] - j - k - z) / 3);
  }
  for (int k = 0; k <= 2; k++)
    for (int z = 0; z <= 2; z++)
      for (int d = 0; d <= 2; d++) wynik = max(wynik, dp[m][k][z][d]);
  printf("%d\n", wynik);
  return 0;
}
