#include <bits/stdc++.h>
using namespace std;
int n, m, a[1000010], f[1000010][5][3];
int main() {
  scanf("%d%d", &n, &m);
  int i, j, k, x;
  for (i = 1; i <= n; i++) {
    scanf("%d", &x);
    a[x]++;
  }
  int t, p, q;
  for (i = 1; i <= m; i++)
    for (j = 0; j <= 4; j++)
      for (k = 0; k <= 2; k++)
        for (f[i][j][k] = 0, t = 0; t <= min(a[i], min(j, k)); t++) {
          p = a[i] - t;
          q = min(j - t, 2);
          f[i][j][k] = max(f[i][j][k], f[i - 1][p % 3][q] + p / 3 + t);
          if (p % 3 == 0 && p >= 3)
            f[i][j][k] = max(f[i][j][k], f[i - 1][3][q] + p / 3 - 1 + t);
          else if (p % 3 == 0 && p >= 6)
            f[i][j][k] = max(f[i][j][k], f[i - 1][4][q] + p / 3 - 2 + t);
          else if (p % 3 == 1 && p >= 4)
            f[i][j][k] = max(f[i][j][k], f[i - 1][4][q] + p / 3 - 1 + t);
          else if (p % 3 == 2 && p >= 5)
            f[i][j][k] = max(f[i][j][k], f[i - 1][4][q] + p / 3 - 1 + t);
        }
  printf("%d\n", f[m][0][0]);
  return 0;
}
