#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
int n, m, a[N], cnt[N], dp[N][3][3];
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    cnt[a[i]]++;
  }
  memset(dp, -0x3f, sizeof(dp));
  dp[0][0][0] = 0;
  for (int i = 1; i <= m + 1; ++i) {
    for (int j = 0; j < 3; ++j) {
      for (int k = 0; k < 3; ++k) {
        if (dp[i - 1][j][k] < 0) continue;
        int now = cnt[i] - j - k;
        for (int t = 0; t < 3 && t <= now; ++t) {
          dp[i][k][t] = max(dp[i][k][t], dp[i - 1][j][k] + (now - t) / 3 + t);
        }
      }
    }
  }
  cout << dp[m + 1][0][0] << endl;
  return 0;
}
