#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m, tmp;
  cin >> n >> m;
  int repeat[m + 2];
  memset(repeat, 0, sizeof(repeat));
  long long dp[m + 2][3][3];
  memset(dp, 0, sizeof(dp));
  for (auto i = 1; i <= n; i++) {
    cin >> tmp;
    repeat[tmp]++;
  }
  for (auto i = 1; i <= m; i++) {
    for (auto j = 0; j <= 2; j++) {
      for (auto k = 0; k <= 2; k++) {
        for (auto l = 0; l <= 2; l++) {
          if (repeat[i] - j - k - l < 0 || repeat[i - 2] - l < 0 ||
              repeat[i - 1] - k - l < 0 || repeat[i + 1] - j - k < 0 ||
              repeat[i + 2] - j < 0)
            break;
          dp[i][j][k] = max(dp[i][j][k],
                            dp[i - 1][k][l] + j + (repeat[i] - j - k - l) / 3);
        }
      }
    }
  }
  cout << dp[m][0][0];
}
