#include <bits/stdc++.h>
using namespace std;
int read() {
  int x = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = x * 10 + c - '0';
    c = getchar();
  }
  return x * f;
}
int n, m;
int i, j, k, l;
int a[1000010];
int sum[1000010];
int f[1000010][4][4];
int main() {
  n = read();
  m = read();
  for (i = 1; i <= n; i++) {
    a[i] = read();
    sum[a[i]]++;
  }
  memset(f, 200, sizeof(f));
  f[0][1][1] = 0;
  for (i = 1; i <= m + 1; i++)
    for (j = 1; j <= 3; j++)
      for (k = 1; k <= 3; k++)
        for (l = 1; l <= 3 && sum[i] - j - k - l + 3 >= 0; l++)
          f[i][k][l] = max(f[i][k][l], f[i - 1][j][k] + l - 1 +
                                           (sum[i] - j - k - l + 3) / 3);
  cout << f[m + 1][1][1] << endl;
}
