#include <bits/stdc++.h>
using namespace std;
int cnt[1000005], d[1000001][3][3];
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; ++i) {
    int u;
    scanf("%d", &u);
    cnt[u]++;
  }
  for (int i = 1; i <= m; ++i)
    for (int j = 0; j <= 2; ++j)
      for (int k = 0; k <= 2; ++k)
        for (int l = 0; l <= 2; ++l)
          if ((i - 2 < 0 || cnt[i - 2] - l >= 0) && cnt[i - 1] - l - j >= 0 &&
              cnt[i] - l - j - k >= 0 && cnt[i + 1] - j - k >= 0 &&
              cnt[i + 2] - k >= 0)
            d[i][j][k] =
                max(d[i][j][k], d[i - 1][l][j] + k + (cnt[i] - l - j - k) / 3);
  printf("%d", d[m][0][0]);
  return 0;
}
