#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 6;
const int ninf = -1e9;
int cnt[N];
int dp[N][3][5];
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  for (int i = 0; i < N; i++)
    for (int j = 0; j < 3; j++)
      for (int k = 0; k < 5; k++) dp[i][j][k] = ninf;
  int n, m;
  cin >> n >> m;
  while (n--) {
    int x;
    cin >> x;
    ++cnt[x];
  }
  dp[0][0][0] = 0;
  for (int i = 1; i <= m; ++i) {
    for (int c = 0; c <= 2; c++)
      for (int b = 0; b <= 2; b++)
        for (int a = 0; a <= 4 && a + c <= cnt[i]; a++) {
          dp[i][b][a] =
              max(dp[i][b][a], (cnt[i] - a - c) / 3 + c + dp[i - 1][c][b + c]);
        }
  }
  cout << dp[m][0][0] << '\n';
}
