#include <bits/stdc++.h>
using namespace std;
const int N = 1000000;
int n, m, x;
int a[N + 100], f[N + 100][3][3];
void init() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &x);
    ++a[x];
  }
}
void checkmax(int &a, int b) {
  if (b > a) a = b;
}
void solve() {
  int ans = 0;
  for (int i = 1; i <= m + 20; ++i) {
    for (int u = 0; u < 3; ++u) {
      for (int v = 0; v < 3; ++v) {
        checkmax(ans, f[i][u][v]);
        for (int w = 0; w < 3; ++w) {
          int U = a[i] - u - v - w, V = a[i + 1] - v - w, W = a[i + 2] - w;
          if (U < 0 || V < 0 || W < 0) continue;
          checkmax(f[i + 1][v][w], f[i][u][v] + w + U / 3);
        }
      }
    }
  }
  printf("%d\n", ans);
}
int main() {
  init();
  solve();
  return 0;
}
