#include <bits/stdc++.h>
using namespace std;
int n, m, d[1000010][3][3];
int cnt[1000010];
void read(int& x) {
  char c = getchar();
  x = 0;
  while (!isdigit(c)) c = getchar();
  while (isdigit(c)) {
    x = x * 10 + c - '0';
    c = getchar();
  }
}
int main() {
  read(n);
  read(m);
  for (int i = 1; i <= n; i++) {
    int x;
    read(x);
    cnt[x]++;
  }
  for (int i = 1; i <= m; i++) {
    for (int j = 0; j <= 2; j++) {
      if (cnt[i - 1] < j || cnt[i] < j || cnt[i + 1] < j) continue;
      for (int k = 0; k <= 2; k++) {
        if (cnt[i] < j + k || cnt[i + 1] < j + k || cnt[i + 2] < k) continue;
        for (int p = 0; p <= 2; p++) {
          bool ok = (i > 1 && cnt[i - 2] >= p) || (!p);
          if (cnt[i] >= p + j + k && ok && cnt[i - 1] >= p + j) {
            d[i][j][k] =
                max(d[i][j][k], d[i - 1][p][j] + (cnt[i] - p - j - k) / 3 + p);
          }
        }
      }
    }
  }
  printf("%d\n", d[m][0][0]);
}
