#include <bits/stdc++.h>
using namespace std;
int n, m;
int cnt[1000010];
int dp[1000010][3][3];
int main(void) {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    cnt[x + 1]++;
  }
  m += 10;
  for (int i = 0; i < m - 2; i++) {
    for (int x = 0; x < 3; x++) {
      for (int y = 0; y < 3; y++) {
        int p = cnt[i] - x - y;
        int q = cnt[i + 1] - y;
        int r = cnt[i + 2];
        for (int z = 0; z < 3; z++) {
          if (p < z || q < z || r < z) continue;
          dp[i + 1][y][z] = max(dp[i + 1][y][z], dp[i][x][y] + z + (p - z) / 3);
        }
      }
    }
  }
  int anss = 0;
  int bb;
  for (int i = 0; i <= m; i++)
    for (int x = 0; x < 3; x++) {
      for (int y = 0; y < 3; y++) {
        anss = max(anss, dp[i][x][y]);
      }
    }
  cout << anss << endl;
  return 0;
}
