#include <bits/stdc++.h>
using namespace std;
const int inf = -(1e9 + 7);
const int N = 1e6 + 5;
int f[2][7][7];
int num[N];
int n, m;
int main() {
  std::ios::sync_with_stdio(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    int a;
    cin >> a;
    num[a]++;
  }
  for (int i = 0; i <= 6; i++)
    if (i <= num[1])
      f[1][0][i] = (num[1] - i) / 3;
    else
      f[1][0][i] = inf;
  for (int j = 1; j <= 6; j++)
    for (int k = 0; k <= 6; k++) f[1][j][k] = inf;
  for (int i = 1; i < m; i++) {
    for (int j = 0; j <= 6; j++)
      for (int k = 0; k <= 6; k++) f[(i + 1) & 1][j][k] = inf;
    for (int j = 0; j <= 6; j++)
      for (int k = 0; k <= 6; k++) {
        if (f[i & 1][j][k] == inf) continue;
        for (int l = 0; l <= 6; l++) {
          if (l > num[i + 1]) continue;
          int v = (num[i + 1] - l) / 3;
          if (j >= 1 && k >= 1 && l >= 1)
            f[(i + 1) & 1][k - 1][l - 1] =
                max(f[(i + 1) & 1][k - 1][l - 1], f[i & 1][j][k] + v + 1);
          if (j >= 2 && k >= 2 && l >= 2)
            f[(i + 1) & 1][k - 2][l - 2] =
                max(f[(i + 1) & 1][k - 2][l - 2], f[i & 1][j][k] + v + 2);
          f[(i + 1) & 1][k][l] = max(f[(i + 1) & 1][k][l], f[i & 1][j][k] + v);
        }
      }
  }
  int ans = 0;
  for (int j = 0; j <= 6; j++)
    for (int k = 0; k <= 6; k++) ans = max(ans, f[m & 1][j][k]);
  cout << ans;
}
