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