#include <bits/stdc++.h>
using namespace std;
using namespace std::placeholders;
using ll = long long;
using ld = long double;
using pr = pair<int, int>;
const int N = 1e6 + 5, MOD = 1e9 + 7;
int a[N], d[3][3][N], n, m;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) {
    int x;
    scanf("%d", &x);
    ++a[x];
  }
  for (int i = 0; i < 3; ++i)
    for (int j = 0; j < 3; ++j)
      for (int k = 0; k < m + 3; ++k) {
        d[i][j][k] = -MOD;
      }
  d[0][0][0] = 0;
  for (int k = 1; k <= m + 2; ++k)
    for (int i = 0; i < 3; ++i)
      for (int j = 0; j < 3; ++j) {
        int mx = 2;
        if (k < 3)
          mx = 0;
        else
          mx = min(mx, min(a[k], min(a[k - 1] - j, a[k - 2] - i - j)));
        for (int p = 0; p < mx + 1; ++p)
          d[j][p][k] = max(d[j][p][k],
                           d[i][j][k - 1] + p +
                               ((k - 2 > 0) ? (a[k - 2] - i - j - p) / 3 : 0));
      }
  int ans = 0;
  for (int i = 0; i < 3; ++i)
    for (int j = 0; j < 3; ++j) ans = max(ans, d[i][j][m + 2]);
  printf("%d\n", ans);
  return 0;
}
