#include <bits/stdc++.h>
using namespace std;
const int N(1e6 + 10);
int n, m, x;
int c[N], dp[N][3][3];
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; ++i) {
    cin >> x;
    c[x]++;
  }
  memset(dp, -1, sizeof dp);
  dp[0][0][0] = 0;
  for (int i = 1; i <= m + 5; ++i) {
    for (int j = 0; j <= 2; ++j) {
      for (int k = 0; k <= 2; ++k) {
        if (dp[i - 1][j][k] == -1) continue;
        int now = c[i] - j - k;
        for (int t = 0; t <= min(2, now); ++t) {
          dp[i][k][t] = max(dp[i][k][t], dp[i - 1][j][k] + t + (now - t) / 3);
        }
      }
    }
  }
  cout << dp[m + 2][0][0] << endl;
  return 0;
}
