#include <bits/stdc++.h>
using namespace std;
const int N = 1000100;
int a[N];
int d[N][3][3];
int main() {
  int n, m, in;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) scanf("%d", &in), a[in]++;
  d[1][0][0] = a[1] / 3;
  d[1][0][1] = ((a[1] && a[2]) && a[3]) * (1 + (a[1] - 1) / 3);
  d[1][0][2] = ((a[1] > 1 && a[2] > 1) && a[3] > 1) * (2 + (a[1] - 2) / 3);
  for (int i = 1; i <= m; ++i)
    for (int t1 = 0; t1 < 3; ++t1)
      for (int t2 = 0; t2 < 3; ++t2)
        for (int t3 = 0; t3 < 3; ++t3)
          if (((a[i] >= t1 + t2) && (a[i + 1] >= t1 + t2 + t3)) &&
              ((a[i + 2] >= t2 + t3) && (a[i + 3] >= t3)))
            d[i + 1][t2][t3] =
                max(d[i + 1][t2][t3],
                    d[i][t1][t2] + (a[i + 1] - t1 - t2 - t3) / 3 + t3);
  int ans(0);
  for (int i = 1; i <= m; ++i) ans = max(ans, d[i][0][0]);
  printf("%d", ans);
  return 0;
}
