#include <bits/stdc++.h>
using namespace std;
int re() {
  int ret = 0, f = 1;
  char ch = getchar();
  while (ch < '0' && '9' < ch) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while ('0' <= ch && ch <= '9') {
    ret = ret * 10 + ch - '0';
    ch = getchar();
  }
  return ret * f;
}
int a[1000100], b[1000100];
int f[1000100][6][3];
int main() {
  int n = re();
  int m = re();
  for (int i = 0; i < n; i++) a[re()]++;
  memset(f, 0, sizeof(f));
  f[0][0][0] = 1;
  for (int i = 0; i <= m; i++) {
    for (int j = 0; j < 6; j++) {
      for (int k = 0; k < 3; k++) {
        if (f[i][j][k]) {
          int num = 2;
          num = min(num, a[i] - j);
          num = min(num, a[i + 1] - k);
          num = min(num, a[i + 2]);
          for (int t = 0; t <= num; t++)
            f[i + 1][k + t][t] =
                max(f[i + 1][k + t][t], f[i][j][k] + t + ((a[i] - j - t) / 3));
        }
      }
    }
  }
  cout << f[m + 1][0][0] - 1 << endl;
  return 0;
}
