#include <bits/stdc++.h>
using namespace std;
const int N = 1000003;
const int M = N;
int n, m, a[M];
int f[2][9][9];
void read(int &x) {
  char ch = getchar();
  x = 0;
  for (; ch < '0' || ch > '9'; ch = getchar())
    ;
  for (; ch >= '0' && ch <= '9'; ch = getchar())
    x = (x << 3) + (x << 1) + ch - '0';
}
inline void checkmax(int &x, int y) {
  if (y > x) x = y;
}
int main() {
  read(n);
  read(m);
  int x;
  for (int i = (1); i <= (n); i++) {
    read(x);
    a[x]++;
  }
  x = a[1] % 3;
  int y = a[2] % 3;
  while (x + 3 <= a[1] && x + 3 <= 8) x += 3;
  while (y + 3 <= a[2] && y + 3 <= 8) y += 3;
  memset(f, -1, sizeof f);
  f[0][x][y] = 0;
  for (int i = (1); i <= (m); i++) {
    f[0][x][y] += a[i] / 3;
    int xx = a[i] % 3;
    while (xx + 3 <= a[i] && xx + 3 <= 8) xx += 3, f[0][x][y]--;
    a[i] = xx;
  }
  f[0][x % 3][y % 3] = f[0][x][y] + x / 3 + y / 3;
  int cur = 1;
  for (int i = (2); i <= (m); i++) {
    memset(f[cur], -1, sizeof f[cur]);
    cur ^= 1;
    for (int j = (8); j >= (0); j--)
      for (int k = (8); k >= (0); k--)
        if (f[cur][j][k] != -1) {
          checkmax(f[cur ^ 1][k][a[i + 1]], f[cur][j][k] + j / 3);
          if (j >= 3) checkmax(f[cur][j - 3][k], f[cur][j][k] + 1);
          for (int l = (0); l <= (8); l++)
            if (j >= l && k >= l && a[i + 1] >= l)
              checkmax(f[cur ^ 1][k - l][a[i + 1] - l], f[cur][j][k] + l);
            else
              break;
        }
  }
  int ans = -1;
  for (int i = (0); i <= (8); i++)
    for (int j = (0); j <= (8); j++)
      if (f[cur][i][j] != -1) checkmax(ans, f[cur][i][j] + i / 3 + j / 3);
  if (m == 1)
    printf("%d\n", a[1] / 3);
  else
    printf("%d\n", ans);
  return 0;
}
